From dd9f132c232c24d939adba5065280fbba0e4ed42 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 20 Oct 2020 16:07:10 +0000 Subject: [github-193] Change TRUNC implementation to use MathX. Thanks to Jacob Harris. This closes #193 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882706 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/formula/functions/TestTrunc.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/testcases/org/apache/poi/ss/formula') diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java index a501435616..c8f4d90f5f 100644 --- a/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java +++ b/src/testcases/org/apache/poi/ss/formula/functions/TestTrunc.java @@ -57,6 +57,21 @@ public final class TestTrunc extends BaseTestNumeric { assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue()); } + @Test + public void testTruncWithProblematicDecimalNumber() { + ValueEval[] args = { new NumberEval(0.29), new NumberEval(2) }; + ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); + assertEquals("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue()); + } + + @Test + public void testTruncWithProblematicCalculationResult() { + + ValueEval[] args = { new NumberEval(21.624d / 24d + .009d), new NumberEval(2) }; + ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); + assertEquals("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue()); + } + @Test public void testTruncWithDecimalNumberOneArg() { ValueEval[] args = { new NumberEval(2.612777) }; -- cgit v1.2.3