From c77f1f9fb9effcb08d4b2796eb631b0c0567052a Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 9 Apr 2022 12:30:49 +0000 Subject: [PATCH] [github-321] Fix issue with rounding in DataFormatter. First try broke a test. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899683 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/ss/usermodel/DataFormatter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java index b14a058aff..78d58e7767 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -803,7 +803,7 @@ public class DataFormatter { if (obj instanceof BigDecimal) { obj = ((BigDecimal) obj).divide(divider, RoundingMode.HALF_UP); } else if (obj instanceof Double) { - obj = (new BigDecimal(NumberToTextConverter.toText((Double)obj))).divide(divider, RoundingMode.HALF_UP); + obj = (Double) obj / divider.doubleValue(); } else { throw new UnsupportedOperationException(); } @@ -948,9 +948,9 @@ public class DataFormatter { Format numberFormat = getFormat(cell, cfEvaluator); double d = cell.getNumericCellValue(); if (numberFormat == null) { - return NumberToTextConverter.toText(d); + return Double.toString(d); } - String formatted = numberFormat.format(new BigDecimal(NumberToTextConverter.toText(d))); + String formatted = numberFormat.format(new BigDecimal(Double.toString(d))); return formatted.replaceFirst("E(\\d)", "E+$1"); // to match Excel's E-notation } -- 2.39.5