NumberFormat canadaFrench = NumberFormat.getCurrencyInstance(Locale.CANADA_FRENCH); NumberFormat canadaEnglish = NumberFormat.getCurrencyInstance(Locale.CANADA); BigDecimal amount = new BigDecimal("123456789.99"); System.out.println(canadaFrench.format(amount)); System.out.println(canadaEnglish.format(amount));
Result:
123 456 789,99 $ $123,456,789.99
If you really don't want to use the default format (with spaces as a thousands separator, not dots), use
DecimalFormatSymbols symbols = ((DecimalFormat) canadaFrench).getDecimalFormatSymbols(); symbols.setGroupingSeparator('.'); ((DecimalFormat) canadaFrench).setDecimalFormatSymbols(symbols);
See, this is all done for you by the NumberFormat class if you give it the correct locale. fr_FR means French, not French. For this you need fr_CA. And en_US means English in the United States, not English in Canada. For this you need en_CA.
source share