diff --git a/components/fpspreadsheet/source/common/fpsfunc.pas b/components/fpspreadsheet/source/common/fpsfunc.pas index 4ce3e13c9..09c99b1a3 100644 --- a/components/fpspreadsheet/source/common/fpsfunc.pas +++ b/components/fpspreadsheet/source/common/fpsfunc.pas @@ -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); diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index 59676d3ac..810bbde89 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -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 diff --git a/components/fpspreadsheet/tests/spreadtestcli.lpi b/components/fpspreadsheet/tests/spreadtestcli.lpi index 6297ae49f..d2b503df1 100644 --- a/components/fpspreadsheet/tests/spreadtestcli.lpi +++ b/components/fpspreadsheet/tests/spreadtestcli.lpi @@ -1,7 +1,7 @@ - + @@ -57,9 +57,10 @@ - - - + + + + @@ -176,7 +177,7 @@ - + @@ -187,7 +188,7 @@ - + @@ -198,7 +199,6 @@ - @@ -208,6 +208,9 @@ + + + diff --git a/components/fpspreadsheet/tests/testcases_calcrpnformula.inc b/components/fpspreadsheet/tests/testcases_calcrpnformula.inc index cf404f778..8d8baaf47 100644 --- a/components/fpspreadsheet/tests/testcases_calcrpnformula.inc +++ b/components/fpspreadsheet/tests/testcases_calcrpnformula.inc @@ -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);