https://bz.apache.org/bugzilla/show_bug.cgi?id=60040
--- Comment #5 from Sebastiaan Blommers <[email protected]> --- I still had trouble with this patch, I reverted to the use of US locale (formats ok) and fix the DecimalFormat symbolics afterwards when all CellNumberFormatter logic has passed. Whenever CellFormat.getInstance is called that format (the object) is cached. Using a local final DecimalFormatSymbols in the CellNumberFormatter is not a good idea (especially when unit testing different locales). I changed the corresponding POI version to 3.15 in this ticket. Unit test with the use of locale public class TestCellFormat { final static Locale NL = new Locale("nl", "NL"); char pound = '\u00A3'; char euro = '\u20AC'; // Accounting -> 0 decimal places, default currency symbol String formatDft = "_-\"$\"* #,##0_-;\\-\"$\"* #,##0_-;_-\"$\"* \"-\"_-;_-@_-"; // Accounting -> 0 decimal places, US currency symbol String formatUS = "_-[$$-409]* #,##0_ ;_-[$$-409]* -#,##0 ;_-[$$-409]* \"-\"_-;_-@_-"; // Accounting -> 0 decimal places, UK currency symbol String formatUK = "_-[$" + pound + "-809]* #,##0_-;\\-[$" + pound + "-809]* #,##0_-;_-[$" + pound + "-809]* \"-\"??_-;_-@_-"; // French style accounting, euro sign comes after not before String formatFR = "_-#,##0* [$" + euro + "-40C]_-;\\-#,##0* [$" + euro + "-40C]_-;_-\"-\"??* [$" + euro + "-40C] _-;_-@_-"; // Dutch style accounting, euro sign comes before String formatNL = "_-\"€\"* #,##0.00_-;\\-\"€\"* #,##0.00_-;_-\"€\"* \"-\"_-;_-@_-"; @Test(enabled = true) public void testAccountingFormatsNL() throws IOException { LocaleUtil.setUserLocale(NL); // Has +ve, -ve and zero rules CellFormat cfDft = CellFormat.getInstance(formatDft); CellFormat cfUS = CellFormat.getInstance(formatUS); CellFormat cfUK = CellFormat.getInstance(formatUK); CellFormat cfFR = CellFormat.getInstance(formatFR); CellFormat cfNL = CellFormat.getInstance(formatNL); // For +ve numbers, should be Space + currency symbol + spaces + whole // number with commas + space // (Except French, which is mostly reversed...) assertEquals(" $ 12 ", cfDft.apply(Double.valueOf(12.33)).text); assertEquals(" $ 12 ", cfUS.apply(Double.valueOf(12.33)).text); assertEquals(" " + pound + " 12 ", cfUK.apply(Double.valueOf(12.33)).text); assertEquals(" 12 " + euro + " ", cfFR.apply(Double.valueOf(12.33)).text); assertEquals(" " + euro + " 12,33 ", cfNL.apply(Double.valueOf(12.33)).text); assertEquals(" $ 16.789 ", cfDft.apply(Double.valueOf(16789.2)).text); assertEquals(" $ 16.789 ", cfUS.apply(Double.valueOf(16789.2)).text); assertEquals(" " + pound + " 16.789 ", cfUK.apply(Double.valueOf(16789.2)).text); assertEquals(" 16.789 " + euro + " ", cfFR.apply(Double.valueOf(16789.2)).text); assertEquals(" " + euro + " 16.789,20 ", cfNL.apply(Double.valueOf(16789.2)).text); assertEquals(" $ - ", cfDft.apply(Double.valueOf(0)).text); assertEquals(" " + euro + " - ", cfNL.apply(Double.valueOf(0)).text); // Test in US locale LocaleUtil.setUserLocale(Locale.US); // For +ve numbers, should be Space + currency symbol + spaces + whole // number with commas + space // (Except French, which is mostly reversed...) assertEquals(" $ 12 ", cfDft.apply(Double.valueOf(12.33)).text); assertEquals(" $ 12 ", cfUS.apply(Double.valueOf(12.33)).text); assertEquals(" " + pound + " 12 ", cfUK.apply(Double.valueOf(12.33)).text); assertEquals(" 12 " + euro + " ", cfFR.apply(Double.valueOf(12.33)).text); assertEquals(" " + euro + " 12.33 ", cfNL.apply(Double.valueOf(12.33)).text); assertEquals(" $ 16,789 ", cfDft.apply(Double.valueOf(16789.2)).text); assertEquals(" $ 16,789 ", cfUS.apply(Double.valueOf(16789.2)).text); assertEquals(" " + pound + " 16,789 ", cfUK.apply(Double.valueOf(16789.2)).text); assertEquals(" 16,789 " + euro + " ", cfFR.apply(Double.valueOf(16789.2)).text); // For -ve numbers, gets a bit more complicated... assertEquals("-$ 12 ", cfDft.apply(Double.valueOf(-12.33)).text); assertEquals(" $ -12 ", cfUS.apply(Double.valueOf(-12.33)).text); assertEquals("-" + pound + " 12 ", cfUK.apply(Double.valueOf(-12.33)).text); assertEquals("-12 " + euro + " ", cfFR.apply(Double.valueOf(-12.33)).text); assertEquals("-$ 16,789 ", cfDft.apply(Double.valueOf(-16789.2)).text); assertEquals(" $ -16,789 ", cfUS.apply(Double.valueOf(-16789.2)).text); assertEquals("-" + pound + " 16,789 ", cfUK.apply(Double.valueOf(-16789.2)).text); assertEquals("-16,789 " + euro + " ", cfFR.apply(Double.valueOf(-16789.2)).text); assertEquals(" " + euro + " 16,789.20 ", cfNL.apply(Double.valueOf(16789.2)).text); assertEquals(" $ - ", cfDft.apply(Double.valueOf(0)).text); assertEquals(" " + euro + " - ", cfNL.apply(Double.valueOf(0)).text); } } -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
