* fixed again ffExponent format in FloatToStrFIntl.

* updated test for FloatToStr.

git-svn-id: trunk@5940 -
This commit is contained in:
yury 2007-01-13 13:52:17 +00:00
parent cfb7a70c66
commit 3b70222574
2 changed files with 26 additions and 21 deletions

View File

@ -1095,10 +1095,8 @@ End;
const const
{$ifdef FPC_HAS_TYPE_EXTENDED} {$ifdef FPC_HAS_TYPE_EXTENDED}
maxdigits = 17; maxdigits = 17;
maxexplen = 4;
{$else} {$else}
maxdigits = 15; maxdigits = 15;
maxexplen = 3;
{$endif} {$endif}
Function FloatToStrFIntl(const Value; format: TFloatFormat; Precision, Digits: Integer; ValueType: TFloatValue; Const FormatSettings: TFormatSettings): String; Function FloatToStrFIntl(const Value; format: TFloatFormat; Precision, Digits: Integer; ValueType: TFloatValue; Const FormatSettings: TFormatSettings): String;
@ -1218,16 +1216,17 @@ Begin
Result[3] := DS Result[3] := DS
else else
Result[2] := DS; Result[2] := DS;
if Digits < 4 then
begin
P:=Pos('E',Result); P:=Pos('E',Result);
if P <> 0 then if P <> 0 then
begin begin
Inc(P, 2); Inc(P, 2);
{ the exponent length is shorted if extended is not supported } if Digits > 4 then
if (Digits > maxexplen) then Digits:=4;
insert(copy('0000',1,Digits-maxexplen),Result,P); Digits:=Length(Result) - P - Digits + 1;
while (Result[P] = '0') and (Digits < maxexplen) do if Digits < 0 then
insert(copy('0000',1,-Digits),Result,P)
else
while (Digits > 0) and (Result[P] = '0') do
begin begin
System.Delete(Result, P, 1); System.Delete(Result, P, 1);
if P > Length(Result) then if P > Length(Result) then
@ -1235,8 +1234,7 @@ Begin
System.Delete(Result, P - 2, 2); System.Delete(Result, P - 2, 2);
break; break;
end; end;
Inc(Digits); Dec(Digits);
end;
end; end;
end; end;
End; End;

View File

@ -23,16 +23,23 @@ begin
end; end;
var var
e: extended;
d: double; d: double;
s: single; s: single;
c: currency; c: currency;
begin begin
e:=1234567890123.4;
d:=12345.12345; d:=12345.12345;
s:=12345.12; s:=12345.12;
c:=12345.1234; c:=12345.1234;
CheckResult(FloatToStrF(e,ffExponent,15,1), '1.23456789012340E+12');
CheckResult(FloatToStrF(d,ffExponent,11,0), '1.2345123450E+4'); CheckResult(FloatToStrF(d,ffExponent,11,0), '1.2345123450E+4');
CheckResult(FloatToStrF(s,ffExponent,8,0), '1.2345120E+4'); CheckResult(FloatToStrF(s,ffExponent,8,0), '1.2345120E+4');
CheckResult(FloatToStrF(s,ffExponent,8,7), '1.2345120E+0004');
CheckResult(FloatToStrF(e,ffExponent,8,3), '1.2345679E+012');
CheckResult(FloatToStrF(c,ffExponent,10,0), '1.234512340E+4'); CheckResult(FloatToStrF(c,ffExponent,10,0), '1.234512340E+4');
CheckResult(FloatToStrF(c,ffExponent,11,2), '1.2345123400E+04');
CheckResult(FloatToStrF(c,ffExponent,10,4), '1.234512340E+0004');
CheckResult(FloatToStrF(-12345.12345,ffExponent,11,0), '-1.2345123450E+4'); CheckResult(FloatToStrF(-12345.12345,ffExponent,11,0), '-1.2345123450E+4');
CheckResult(FloatToStrF(-0.00000123,ffGeneral,15,0), '-1.23E-6'); CheckResult(FloatToStrF(-0.00000123,ffGeneral,15,0), '-1.23E-6');
CheckResult(FloatToStrF(-12345.12345,ffGeneral,7,0), '-12345.12'); CheckResult(FloatToStrF(-12345.12345,ffGeneral,7,0), '-12345.12');