aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
diff options
context:
space:
mode:
authorDavid North <dnorth@apache.org>2015-10-06 09:56:26 +0000
committerDavid North <dnorth@apache.org>2015-10-06 09:56:26 +0000
commit940f3c5af39ce547f063b694b9404394301c5844 (patch)
treeeb2318db82cfebcb59f047d7ab14a9e9cd89c36f /src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
parent72bae7a1e66f911a631b8b6cfc7aa69125babcac (diff)
downloadpoi-940f3c5af39ce547f063b694b9404394301c5844.tar.gz
poi-940f3c5af39ce547f063b694b9404394301c5844.zip
Format numbers more like Excel does
Thanks to Chris Boyle for the patch https://bz.apache.org/bugzilla/show_bug.cgi?id=58471 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1706971 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
index 3b2588f075..dbb99c0a86 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
@@ -171,7 +171,8 @@ public final class TestHSSFDataFormatter {
// create cells with bad num patterns
for (int i = 0; i < badNumPatterns.length; i++) {
HSSFCell cell = row.createCell(i);
- cell.setCellValue(1234567890.12345);
+ // If the '.' is any later, ExcelGeneralNumberFormat will render an integer, as Excel does.
+ cell.setCellValue(12345678.9012345);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat(badNumPatterns[i]));
cell.setCellStyle(cellStyle);
@@ -276,10 +277,11 @@ public final class TestHSSFDataFormatter {
log("\n==== VALID NUMBER FORMATS ====");
while (it.hasNext()) {
HSSFCell cell = (HSSFCell) it.next();
- log(formatter.formatCellValue(cell));
+ final String formatted = formatter.formatCellValue(cell);
+ log(formatted);
- // should not be equal to "1234567890.12345"
- assertTrue( ! "1234567890.12345".equals(formatter.formatCellValue(cell)));
+ // should not include "12345678" - note that the input value was negative
+ assertTrue(formatted != null && ! formatted.contains("12345678"));
}
// test bad number formats
@@ -289,10 +291,9 @@ public final class TestHSSFDataFormatter {
while (it.hasNext()) {
HSSFCell cell = (HSSFCell) it.next();
log(formatter.formatCellValue(cell));
- // should be equal to "1234567890.12345"
// in some locales the the decimal delimiter is a comma, not a dot
char decimalSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getDecimalSeparator();
- assertEquals("1234567890" + decimalSeparator + "12345", formatter.formatCellValue(cell));
+ assertEquals("12345678" + decimalSeparator + "9", formatter.formatCellValue(cell));
}
// test Zip+4 format