bug 59638: patch from Axel Howind, support non-comma number grouping separators (such as German 1.234,57)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a749f7f3f5
commit
74be4d4174
@ -674,13 +674,18 @@ public class DataFormatter implements Observer {
|
|||||||
// eg for a format like #'##0 which wants 12'345 not 12,345
|
// eg for a format like #'##0 which wants 12'345 not 12,345
|
||||||
Matcher agm = alternateGrouping.matcher(format);
|
Matcher agm = alternateGrouping.matcher(format);
|
||||||
if (agm.find()) {
|
if (agm.find()) {
|
||||||
symbols = DecimalFormatSymbols.getInstance(locale);
|
|
||||||
|
|
||||||
char grouping = agm.group(2).charAt(0);
|
char grouping = agm.group(2).charAt(0);
|
||||||
symbols.setGroupingSeparator(grouping);
|
// Only replace the grouping character if it is not the default
|
||||||
String oldPart = agm.group(1);
|
// grouping character for the US locale (',') in order to enable
|
||||||
String newPart = oldPart.replace(grouping, ',');
|
// correct grouping for non-US locales.
|
||||||
format = format.replace(oldPart, newPart);
|
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 {
|
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
|
* Ensure that colours get correctly
|
||||||
* zapped from within the format strings
|
* zapped from within the format strings
|
||||||
|
Loading…
Reference in New Issue
Block a user