diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java index ba89baed3d..63faef0c91 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java @@ -31,6 +31,7 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; @@ -148,7 +149,7 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat { assertEquals("TRUE", df.formatCellValue(cell)); CellStyle cellStyle = wb.createCellStyle(); - cellStyle.setDataFormat((short)14); + cellStyle.setDataFormat((short) 14); cell.setCellStyle(cellStyle); cell.setCellValue(new Date(234092383)); assertEquals("1/3/70", df.formatCellValue(cell)); @@ -159,5 +160,19 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat { */ } } - + + @Test + public void testGitHub650() throws IOException { + // https://github.com/apache/poi/pull/650 + DataFormatter df = new DataFormatter(); + + try (Workbook wb = _testDataProvider.openSampleWorkbook("decimal-format.xlsx")) { + Sheet sheet = wb.getSheetAt(0); + Cell cell1 = sheet.getRow(0).getCell(0); + assertEquals("1.01", df.formatCellValue(cell1)); + Cell cell2 = sheet.getRow(1).getCell(0); + assertEquals("1.00", df.formatCellValue(cell2)); + } + } + } diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java index 77ac9154d7..e037b83f98 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java @@ -38,7 +38,7 @@ public abstract class BaseTestDataFormat { protected static final String POUND_FMT = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0"; - private final ITestDataProvider _testDataProvider; + protected final ITestDataProvider _testDataProvider; protected BaseTestDataFormat(ITestDataProvider testDataProvider) { _testDataProvider = testDataProvider; diff --git a/test-data/spreadsheet/decimal-format.xlsx b/test-data/spreadsheet/decimal-format.xlsx new file mode 100644 index 0000000000..72484c9c31 Binary files /dev/null and b/test-data/spreadsheet/decimal-format.xlsx differ