首页 > 解决方案 > Format amount in Canadian for finance area

问题描述

I am trying to format an amount for Canadian locale 'en_CA' for finances area. But in java, it uses the ¤#,##0.00 pattern for 'en_CA' locale. This pattern is correct but is used for general texts.
In the area of finance, it should be another pattern with whitespace after a currency symbol.
Like ¤ #,##0.00.
For example: CAD 125,456.00
I've tried this way:

DecimalFormat currencyInstance = ( DecimalFormat ) DecimalFormat.getCurrencyInstance( new Locale( "en", "CA" ) );
DecimalFormatSymbols decimalFormatSymbols = currencyInstance.getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol( "CAD" );
currencyInstance.setDecimalFormatSymbols( decimalFormatSymbols );
System.out.println( currencyInstance.format( 123456 ) );
System.out.println( currencyInstance.toLocalizedPattern() ); // get pattern

I get result without whitespace:

CAD123,456.00
¤#,##0.00

So my question if Java contains a pattern for the 'en_CA' locale for financial area? How can I find it? I know that I can set my own pattern to DecimalFormat but I am looking for a solution when Java will provide that pattern for me.

标签: javaformatlocalecurrency

解决方案


推荐阅读