diff --git a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs index 512b609..c4e86ca 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs @@ -470,13 +470,13 @@ var digits = (Int32)(Double)p[1]; if (digits >= 0) { - return Math.Round(value, digits); + return Math.Round(value, digits, MidpointRounding.AwayFromZero); } else { digits = Math.Abs(digits); double temp = value / Math.Pow(10, digits); - temp = Math.Round(temp, 0); + temp = Math.Round(temp, 0, MidpointRounding.AwayFromZero); return temp * Math.Pow(10, digits); } diff --git a/ClosedXML_Tests/Excel/CalcEngine/FunctionsTests.cs b/ClosedXML_Tests/Excel/CalcEngine/FunctionsTests.cs index ce5ae67..c0035ee 100644 --- a/ClosedXML_Tests/Excel/CalcEngine/FunctionsTests.cs +++ b/ClosedXML_Tests/Excel/CalcEngine/FunctionsTests.cs @@ -379,6 +379,12 @@ actual = XLWorkbook.EvaluateExpr("Round(-50.55, -2)"); Assert.AreEqual(-100.0, actual); + + actual = XLWorkbook.EvaluateExpr("ROUND(59 * 0.535, 2)"); // (59 * 0.535) = 31.565 + Assert.AreEqual(31.57, actual); + + actual = XLWorkbook.EvaluateExpr("ROUND(59 * -0.535, 2)"); // (59 * -0.535) = -31.565 + Assert.AreEqual(-31.57, actual); } [Test]