java - 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.
解决方案
推荐阅读
- c# - 创建文本文档时拒绝访问文档文件夹的路径
- java - JPA 强制插入相关实体(而不是更新)
- c - 如何防止程序被套接字listen()阻塞
- css - 如何让 flexbox 容器缩放我的页面?
- c - 在结构中使用点运算符与箭头运算符和字符串指针
- java - com.restApi.java.jpa.UserDaoServiceCommandLineRunner 中的字段 userDAOService 需要找不到类型为“service.UserDAOService”的 bean
- javascript - 当我尝试使用 laravel 发布表单时,控制台显示“不正确的整数值”。无法识别路由参数
- python - 切片分配的 Numpy 切片意外失败
- typescript - 执行每个函数直到返回“真实”值的组合函数
- android-studio - Flutter - 直接从 Android Studio [配置] 运行/调试桌面应用程序