Skip to content

Commit

Permalink
Fix RoundDown function
Browse files Browse the repository at this point in the history
Closes #1198
  • Loading branch information
Bykiev committed May 1, 2024
1 parent 3ddd12a commit 6ae51ea
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main/NPOI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Enums.NET" Version="4.0.1" />
<PackageReference Include="ExtendedNumerics.BigDecimal" Version="2023.1000.4.35" />
<PackageReference Include="ExtendedNumerics.BigDecimal" Version="2025.1000.2.122" />
<PackageReference Include="MathNet.Numerics.Signed" Version="5.0.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
Expand Down
7 changes: 1 addition & 6 deletions main/SS/Formula/Functions/MathX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,8 @@ public static double RoundDown(double n, int p)
{
if(p != 0)
{
var temp = BigDecimal.Pow(10, p);
var value = new BigDecimal(n);
var absValue = BigDecimal.Abs(value);
var multValue = BigDecimal.Multiply(absValue, temp);
var roundingValue = BigDecimal.Subtract(multValue, new BigDecimal(0.5));
var roundedValue = BigDecimal.Round(roundingValue, MidpointRounding.AwayFromZero);
retval = Sign(n) * ((double)BigDecimal.Divide(roundedValue, temp));
retval = (double)BigDecimal.Round(value, p);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion testcases/main/SS/Formula/Functions/TestMathX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public void TestRoundDown()
d = Double.MinValue; p = 1;
AssertEquals("roundDown ", 0.0d, MathX.RoundDown(d, p));

d = 17.56;
d = 17.56; p = 2;
AssertEquals("roundDown ", 17.56, MathX.RoundDown(d, p));
}
[Test]
Expand Down

0 comments on commit 6ae51ea

Please # to comment.