From 9a97204dc8cd4613f43480359243221bdecfe15e Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 3 Feb 2022 10:05:38 +0000 Subject: [PATCH] add INT tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897715 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/functions/NumericFunction.java | 1 + .../poi/ss/formula/functions/TestNumericFunction.java | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java index 1ba040e4da..557fbc7893 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java @@ -100,6 +100,7 @@ public abstract class NumericFunction implements Function { public static final Function EXP = oneDouble(d -> Math.pow(Math.E, d)); public static final Function FACT = oneDouble(MathX::factorial); + //https://support.microsoft.com/en-us/office/int-function-a6c4af9e-356d-4369-ab6a-cb1fd9d343ef public static final Function INT = oneDouble(d -> Math.round(d-0.5)); public static final Function LN = oneDouble(Math::log); public static final Function LOG10 = oneDouble(d -> Math.log(d) / LOG_10_TO_BASE_e); diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java index bdb75f027f..77d204aeff 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestNumericFunction.java @@ -30,8 +30,12 @@ final class TestNumericFunction { HSSFWorkbook wb = new HSSFWorkbook(); HSSFCell cell = wb.createSheet().createRow(0).createCell(0); HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); - assertDouble(fe, cell, "880000000*0.00849", 7471200.0, 0.00000001); - assertDouble(fe, cell, "880000000*0.00849/3", 2490400.0, 0.00000001); - assertDouble(fe, cell, "INT(880000000*0.00849/3)", 2490400.0, 0.00000001); + assertDouble(fe, cell, "INT(880000000.0001)", 880000000.0, 0); + //the following INT(-880000000.0001) resulting in -880000001.0 has been observed in excel + //see also https://support.microsoft.com/en-us/office/int-function-a6c4af9e-356d-4369-ab6a-cb1fd9d343ef + assertDouble(fe, cell, "INT(-880000000.0001)", -880000001.0, 0); + assertDouble(fe, cell, "880000000*0.00849", 7471200.0, 0); + assertDouble(fe, cell, "880000000*0.00849/3", 2490400.0, 0); + assertDouble(fe, cell, "INT(880000000*0.00849/3)", 2490400.0, 0); } } -- 2.39.5