git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747139 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_15_BETA2
@@ -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 { |
@@ -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 |