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

View File

@ -23,16 +23,23 @@ begin
end;
var
e: extended;
d: double;
s: single;
c: currency;
begin
e:=1234567890123.4;
d:=12345.12345;
s:=12345.12;
c:=12345.1234;
CheckResult(FloatToStrF(e,ffExponent,15,1), '1.23456789012340E+12');
CheckResult(FloatToStrF(d,ffExponent,11,0), '1.2345123450E+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,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(-0.00000123,ffGeneral,15,0), '-1.23E-6');
CheckResult(FloatToStrF(-12345.12345,ffGeneral,7,0), '-12345.12');