From 4bcf9d8eb93ab8331905b586591be7abeb0aa1db Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 2 Nov 2018 09:38:20 +0000 Subject: [PATCH] * Fix formatfloat digits after decimalsepararor in case of 0 --- packages/rtl/sysutils.pas | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/rtl/sysutils.pas b/packages/rtl/sysutils.pas index 7b9a0d7..8856a0e 100644 --- a/packages/rtl/sysutils.pas +++ b/packages/rtl/sysutils.pas @@ -27,13 +27,15 @@ type {***************************************************************************** Various types *****************************************************************************} +Const + FloatRecDigits = 19; type { TFloatRec } TFloatRec = Record Exponent: Integer; Negative: Boolean; - Digits: Array[0..18] Of Char; + Digits: Array[0..FloatRecDigits-1] Of Char; End; TEndian = (Little,Big); TFileName = String; @@ -679,7 +681,7 @@ end; Function FloatToDecimal(Value : double; Precision, Decimals : integer) : TFloatRec; Const - Rounds = '1234567890'; + Rounds = '123456789:'; var Buffer: String; //Though str func returns only 25 chars, this might change in the future @@ -688,6 +690,10 @@ var GotNonZeroBeforeDot, BeforeDot : boolean; begin + Result.Negative:=False; + Result.Exponent:=0; + For C:=0 to FloatRecDigits do + Result.Digits[C]:='0'; if Value=0 then exit; asm @@ -752,7 +758,7 @@ begin end; // Calculate number of digits we have from str N:=OutPos; -// Writeln('Number of digits: ',N,' requested precision : ',Precision); + // Writeln('Number of digits: ',N,' requested precision : ',Precision); L:=Length(Result.Digits); While N= L Then N := L-1; -// Writeln('Rounding on digit : ',N); + // Writeln('Rounding on digit : ',N); if N = 0 Then begin if Result.Digits[0] >= '5' Then @@ -787,7 +793,7 @@ begin // Writeln(N,': ',Result.Digits[N],', Rounding to : ',Rounds[StrToInt(Result.Digits[N])]); Result.Digits[N]:=Rounds[StrToInt(Result.Digits[N])+1]; Until (N = 0) Or (Result.Digits[N] < ':'); - If Result.Digits[0] = '0' Then + If Result.Digits[0] = ':' Then begin Result.Digits[0] := '1'; Inc(Result.Exponent); @@ -955,7 +961,7 @@ var // Copy a digit (#, 0) to the output with the correct value begin - // Writeln('CopyDigit '); + // Writeln('CopyDigit: Padzeroes: ',PadZeroes,', DistToDecimal: ',DistToDecimal); if (PadZeroes=0) then WriteDigit(GetDigit) // No shift needed, just copy what is available. else if (PadZeroes<0) then @@ -1125,8 +1131,9 @@ var FV:=FloatToDecimal(aValue,P,D); // Writeln('Number of digits available : ',Length(FV.Digits)); // For p:=0 to Length(FV.Digits)-1 do - // writeln(P,': ',FV.Digits[p]); + // Writeln(P,': ',FV.Digits[p]); DistToDecimal:=DecimalPos-1; + // Writeln('DistToDecimal : ',DistToDecimal); if IsScientific then PadZeroes:=0 // No padding. else