Skip to content

Commit

Permalink
Fix ROUNDDOWN function
Browse files Browse the repository at this point in the history
Fix ROUNDDOWN function
  • Loading branch information
Bykiev committed Apr 5, 2024
1 parent 649c565 commit 1ae954a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main/SS/Formula/Functions/MathX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public static double RoundDown(double n, int p)
{
if (p != 0)
{
double temp = Math.Pow(10, p);
retval = Sign(n) * Math.Round((Math.Abs(n) * temp) - 0.5, MidpointRounding.AwayFromZero) / temp;
decimal temp = Convert.ToDecimal(Math.Pow(10, p));
retval = Convert.ToDouble(Math.Floor(((decimal)n) * temp) / temp);
}
else
{
Expand Down
13 changes: 13 additions & 0 deletions testcases/ooxml/XSSF/UserModel/TestXSSFFormulaEvaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,19 @@ public void EvaluateInCellReturnsSameDataType()
Assert.AreSame(cell, same);
wb.Close();
}

[Test]
public void TestRoundDown()
{
IWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("Rounddown_Issue.xlsx");
var sheet = wb.GetSheetAt(0);
var formula = new XSSFFormulaEvaluator(wb);
formula.EvaluateAll();
var cellReference = new CellReference("Q13");
var row = sheet.GetRow(cellReference.Row);
var cell = row.GetCell(cellReference.Col);
Assert.AreEqual(17.56, cell.NumericCellValue, 0.00000001);
}
}

}
Binary file not shown.

0 comments on commit 1ae954a

Please sign in to comment.