fpspreadsheet: Fix number format test case. Now all tests are passed again.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6060 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-11-06 08:35:25 +00:00
parent 6107fd43de
commit 515e7437e5
2 changed files with 22 additions and 3 deletions

View File

@ -900,6 +900,22 @@ end;
-------------------------------------------------------------------------------}
function ConvertFloatToStr(AValue: Double; AParams: TsNumFormatParams;
AFormatSettings: TFormatSettings): String;
{ Returns true if s represent the value 0; it can be written in various
ways: '0', '0.00', '0,000.0', '0.00E+10' etc. }
function IsZeroStr(s: String): Boolean;
var
i: Integer;
begin
Result := false;
for i:=1 to Length(s) do
case s[i] of
'e', 'E': break;
'1'..'9': exit;
end;
Result := true;
end;
var
fs: TFormatSettings absolute AFormatSettings;
sidx: Integer;
@ -961,7 +977,7 @@ begin
else
// Floating-point or integer
s := ProcessFloatFormat(AValue, fs, section.Elements, el);
if (sidx = 0) and isNeg then s := '-' + s;
if (sidx = 0) and isNeg and not IsZeroStr(s) then s := '-' + s;
Result := Result + s;
Continue;
end

View File

@ -225,8 +225,11 @@ begin
SollNumberStrings[i, 0] := FloatToStr(SollNumbers[i], fs);
SollNumberStrings[i, 1] := FormatFloat('0', SollNumbers[i], fs);
SollNumberStrings[i, 2] := FormatFloat('0.00', SollNumbers[i], fs);
SollNumberStrings[i, 3] := FormatFloat('#,##0', SollNumbers[i], fs);
SollNumberStrings[i, 4] := FormatFloat('#,##0.00', SollNumbers[i], fs);
// For the next two cases don't use FormatFloat('#,##0') and
// FormatFloat('#,##0.00') which produce '-0' and '-0.00', respectively,
// for the case of -1.23456E-6 which is not consistent with Excel.
SollNumberStrings[i, 3] := Format('%.0n', [SollNumbers[i]], fs);
SollNumberStrings[i, 4] := Format('%.2n', [SollNumbers[i]], fs);
SollNumberStrings[i, 5] := FormatFloat('0.00E+00', SollNumbers[i], fs);
SollNumberStrings[i, 6] := FormatFloat('0', SollNumbers[i]*100, fs) + '%';
SollNumberStrings[i, 7] := FormatFloat('0.00', SollNumbers[i]*100, fs) + '%';