// 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 {
}
+
+ /**
+ * 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