ASF Bugzilla – Attachment 33921 Details for
Bug 59638
org.apache.poi.ss.usermodel.DataFormatter forces a comma as a grouping separator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
proposed fix and test cases (patch)
bug59638.patch (text/plain), 2.70 KB, created by
Axel Howind
on 2016-06-06 21:22:50 UTC
(
hide
)
Description:
proposed fix and test cases (patch)
Filename:
MIME Type:
Creator:
Axel Howind
Created:
2016-06-06 21:22:50 UTC
Size:
2.70 KB
patch
obsolete
>diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java >index 6f0d830..a20d083 100644 >--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java >+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java >@@ -674,13 +674,18 @@ public class DataFormatter implements Observer { > // eg for a format like #'##0 which wants 12'345 not 12,345 > Matcher agm = alternateGrouping.matcher(format); > if (agm.find()) { >- symbols = DecimalFormatSymbols.getInstance(locale); >- > char grouping = agm.group(2).charAt(0); >- symbols.setGroupingSeparator(grouping); >- String oldPart = agm.group(1); >- String newPart = oldPart.replace(grouping, ','); >- format = format.replace(oldPart, newPart); >+ // Only replace the grouping character if it is not the default >+ // grouping character for the US locale (',') in order to enable >+ // correct grouping for non-US locales. >+ if (grouping!=',') { >+ symbols = DecimalFormatSymbols.getInstance(locale); >+ >+ symbols.setGroupingSeparator(grouping); >+ String oldPart = agm.group(1); >+ String newPart = oldPart.replace(grouping, ','); >+ format = format.replace(oldPart, newPart); >+ } > } > > try { >diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java >index bc9ebed..d827355 100644 >--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java >+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java >@@ -82,6 +82,25 @@ public class TestDataFormatter { > > } > >+ >+ /** >+ * Test that we use the specified locale when deciding >+ * how to format normal numbers >+ */ >+ @Test >+ public void testGrouping() { >+ DataFormatter dfUS = new DataFormatter(Locale.US); >+ DataFormatter dfDE = new DataFormatter(Locale.GERMAN); >+ >+ assertEquals("1,234.57", dfUS.formatRawCellContents(1234.567, -1, "#,##0.00")); >+ assertEquals("1'234.57", dfUS.formatRawCellContents(1234.567, -1, "#'##0.00")); >+ assertEquals("1 234.57", dfUS.formatRawCellContents(1234.567, -1, "# ##0.00")); >+ >+ assertEquals("1.234,57", dfDE.formatRawCellContents(1234.567, -1, "#,##0.00")); >+ assertEquals("1'234,57", dfDE.formatRawCellContents(1234.567, -1, "#'##0.00")); >+ assertEquals("1 234,57", dfDE.formatRawCellContents(1234.567, -1, "# ##0.00")); >+ } >+ > /** > * Ensure that colours get correctly > * zapped from within the format strings
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 59638
:
33899
| 33921