fpspreadsheet: Fix error in Round function. Add a second unit test for Round.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6217 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-02-27 22:21:49 +00:00
parent 8976969236
commit 022b837553
4 changed files with 35 additions and 11 deletions

View File

@ -315,7 +315,7 @@ begin
n := Args[1].ResInteger
else
n := round(Args[1].ResFloat);
Result := FloatResult(RoundTo(ArgToFloat(Args[0]), n));
Result := FloatResult(RoundTo(ArgToFloat(Args[0]), -n));
end;
procedure fpsSIGN(var Result: TsExpressionResult; const Args: TsExprParameterArray);

View File

@ -2963,6 +2963,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
nf: TsNumberFormat;
nfs: String;
decs: Byte;
sint: String;
s: String;
f: Double;
fracInt, fracNum, fracDenom: Integer;
@ -2986,6 +2987,9 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
end else
if nodeName = 'number:number' then
begin
sint := GetAttrValue(node, 'number:min-integer-digits');
if sint = '' then sint := '1';
s := GetAttrValue(node, 'number:decimal-places');
if s = '' then
s := GetAttrValue(node, 'decimal-places');
@ -3000,7 +3004,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
s := GetAttrValue(node, 'number:display-factor');
if s <> '' then f := StrToFloat(s, FPointSeparatorSettings) else f := 1.0;
nf := IfThen(grouping, nfFixedTh, nfFixed);
nfs := nfs + BuildNumberFormatString(nf, Workbook.FormatSettings, decs);
nfs := nfs + BuildNumberFormatString(nf, Workbook.FormatSettings, decs); //, StrToInt(sint));
if f <> 1.0 then begin
nf := nfCustom;
while (f > 1.0) do

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<Version Value="11"/>
<PathDelim Value="\"/>
<General>
<Flags>
@ -57,9 +57,10 @@
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>
@ -176,7 +177,7 @@
<Filename Value="spreadtestcli"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<IncludeFiles Value="..\source;$(ProjOutDir)"/>
<OtherUnitFiles Value="..\source\common;..\source\visual;..\source\export"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
@ -187,7 +188,7 @@
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="5">
<Exceptions Count="6">
<Item1>
<Name Value="ECodetoolError"/>
<Enabled Value="False"/>
@ -198,7 +199,6 @@
</Item2>
<Item3>
<Name Value="EAssertionFailedError"/>
<Enabled Value="False"/>
</Item3>
<Item4>
<Name Value="Exception"/>
@ -208,6 +208,9 @@
<Name Value="EIBDatabaseError"/>
<Enabled Value="False"/>
</Item5>
<Item6>
<Name Value="EIgnoredTest"/>
</Item6>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -1586,9 +1586,26 @@
RPNFunc('ROUND', nil)))))
else
myWorksheet.WriteFormula(Row, 1, formula);
myWorksheet.WriteNumber(Row, 2, RoundTo(pi, 2));
// NOTE: Excel and FPS have different signs in number of digits
myWorksheet.WriteNumber(Row, 2, RoundTo(pi, -2));
SetLength(sollValues, Row+1);
sollValues[Row] := FloatResult(RoundTo(pi, 2));
sollValues[Row] := FloatResult(RoundTo(pi, -2));
// ROUND
inc(Row);
formula := 'ROUND(12345.6789,-2)';
MyWorksheet.WriteUTF8Text(Row, 0, formula);
if UseRPNFormula then
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
RPNNumber(12345.6789,
RPNNumber(-2,
RPNFunc('ROUND', nil)))))
else
myWorksheet.WriteFormula(Row, 1, formula);
// NOTE: Excel and FPS have different signs in number of digits
myWorksheet.WriteNumber(Row, 2, RoundTo(12345.6789, 2));
SetLength(sollValues, Row+1);
sollValues[Row] := FloatResult(RoundTo(12345.6789, 2));
// SIGN
inc(Row);