]> source.dussan.org Git - poi.git/commitdiff
partial implementation FLOOR.MATH function (needs more testing and bad param support)
authorPJ Fanning <fanningpj@apache.org>
Mon, 23 May 2022 14:02:47 +0000 (14:02 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 23 May 2022 14:02:47 +0000 (14:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901173 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/formula/functions/FloorMath.java
poi/src/test/java/org/apache/poi/ss/formula/functions/TestFloorMath.java

index 0b0d13928b5574ef356d8229cdec9d7c48654225..71376f4cb178f61cec712f424da07829e5b3c173 100644 (file)
@@ -62,12 +62,14 @@ public final class FloorMath implements FreeRefFunction {
             }
             if (roundNegativeNumsDown && xval < 0.0) {
                 if (multiplier != 1.0) {
-                    return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, RoundingMode.CEILING));
+                    RoundingMode mode = multiplier < 0.0 ? RoundingMode.FLOOR : RoundingMode.CEILING;
+                    return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, mode));
                 }
                 return new NumberEval(Math.ceil(xval));
             }
             if (multiplier != 1.0) {
-                return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, RoundingMode.FLOOR));
+                RoundingMode mode = multiplier < 0.0 ? RoundingMode.CEILING : RoundingMode.FLOOR;
+                return new NumberEval(scaledRoundUsingBigDecimal(xval, multiplier, mode));
             }
             return new NumberEval(Math.floor(xval));
         } catch (EvaluationException evaluationException) {
index b1712619695e86c021c9678d9f19f3b2603f5da2..8973fe71461e45b60a43adc88750966dfa826fac 100644 (file)
@@ -47,6 +47,10 @@ final class TestFloorMath {
             assertDouble(fe, cell, "FLOOR.MATH(6.7)", 6.0, 0.00000000000001);
             assertDouble(fe, cell, "FLOOR.MATH(-8.1,2)", -10.0, 0.00000000000001);
             assertDouble(fe, cell, "FLOOR.MATH(-5.5,2,-1)", -4.0, 0.00000000000001);
+
+            assertDouble(fe, cell, "FLOOR.MATH(-2.5,-2)", -4.0, 0.00000000000001);
+            assertDouble(fe, cell, "FLOOR.MATH(-2.5,-2,-1)", -2.0, 0.00000000000001);
+            assertDouble(fe, cell, "FLOOR.MATH(2.5,-2)", 2.0, 0.00000000000001);
         }
     }