From d14dc1c659d82baae76fa92ba1e43cb169141580 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 18 Oct 2021 22:40:14 +0000 Subject: [PATCH] scaling issue git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894366 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/tests/format/TestCellFormatPart.java | 4 ++-- .../java/org/apache/poi/ss/format/CellNumberFormatter.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java index e49021f578..101fa6c10e 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ss/tests/format/TestCellFormatPart.java @@ -46,11 +46,11 @@ import org.junit.jupiter.api.Test; /** * Class for spreadsheet-based tests, such as are used for cell formatting. * This reads tests from the spreadsheet, as well as reading - * flags that can be used to paramterize these tests. + * flags that can be used to parameterize these tests. *

* Each test has four parts: The expected result (column A), the format string * (column B), the value to format (column C), and a comma-separated list of - * categores that this test falls in. Normally all tests are run, but if the + * categories that this test falls in. Normally all tests are run, but if the * flag "Categories" is not empty, only tests that have at least one category * listed in "Categories" are run. */ diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellNumberFormatter.java b/poi/src/main/java/org/apache/poi/ss/format/CellNumberFormatter.java index 2da55efe90..3f37dc5553 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/poi/src/main/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.ss.format; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.FieldPosition; @@ -424,8 +425,8 @@ public class CellNumberFormatter extends CellFormatter { @Override public void formatValue(StringBuffer toAppendTo, Object valueObject) { - double value = ((Number) valueObject).doubleValue(); - value *= scale; + BigDecimal bd = BigDecimal.valueOf(((Number) valueObject).doubleValue()).multiply(BigDecimal.valueOf(scale)); + double value = bd.doubleValue(); // For negative numbers: // - If the cell format has a negative number format, this method