From 3b70222574e6dd5c26446de3b4aa8445e43dc9b9 Mon Sep 17 00:00:00 2001 From: yury Date: Sat, 13 Jan 2007 13:52:17 +0000 Subject: [PATCH] * fixed again ffExponent format in FloatToStrFIntl. * updated test for FloatToStr. git-svn-id: trunk@5940 - --- rtl/objpas/sysutils/sysstr.inc | 40 +++++++++++------------- tests/test/units/sysutils/tfloattostr.pp | 7 +++++ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/rtl/objpas/sysutils/sysstr.inc b/rtl/objpas/sysutils/sysstr.inc index d2ed5cd52f..aea342c32b 100644 --- a/rtl/objpas/sysutils/sysstr.inc +++ b/rtl/objpas/sysutils/sysstr.inc @@ -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; diff --git a/tests/test/units/sysutils/tfloattostr.pp b/tests/test/units/sysutils/tfloattostr.pp index 050eacd25c..be299a9eab 100644 --- a/tests/test/units/sysutils/tfloattostr.pp +++ b/tests/test/units/sysutils/tfloattostr.pp @@ -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');