java - 使用 ISO 4217 的 CurrencyCode 格式化 pl_PL 价格
问题描述
我需要BigDecimal
根据 ISO 4217 将价格(as )格式化为波兰货币格式。根据https://en.wikipedia.org/wiki/ISO_4217#Active_codes和我的接受标准,这种格式应该始终有 2 位小数。
所以我有 pl_PL 的 Java-Locale 对象和相关CurrencyUnit 985
的 from ISO 4217
,我可以在调试器中看到。现在,当我想格式化以下价格时,我遇到了一些问题:
- 12.34000 => 12.34(正常)
- 12.500 => 12.5(不好,预期为 12.50)
- 12.000 => 12(不好,预期为 12.00)
所以我做了一些调试,我发现Java从类中读取了pl_PL
相关的定价,它的定义如下:DecimalPattern
FormatData_pl_PL.java
{ "NumberPatterns",
new String[] {
"#,##0.###;-#,##0.###", // decimal pattern
"#,##0.## \u00A4;-#,##0.## \u00A4", // currency pattern
"#,##0%" // percent pattern
}
},
上面的模式将在这种情况下使用:
NumberFormat format = NumberFormat.getCurrencyInstance(locale);
DecimalFormat decimalFormat = (DecimalFormat) format;
String pattern = getSimplePattern(locale, currency);
decimalFormat.applyPattern(pattern);
return decimalFormat.format(price);
所以给定的货币模式似乎不正确。按照ISO 4217
它应该是"#,##0.00"
,不是吗?
我该如何处理这个问题?
解决方案
推荐阅读
- php - Yii2 移除初始搜索
- sql - 如何根据规则获取逐年数据
- php - 使用 mailx 通过 mail() PHP 发送 HTML
- dart - Flutter 和 Firestore:如何从 Stateful Widget 访问变量来创建新文档?
- pentaho - 打开团队存储库时,Spoon 中经常缺少 .type.xml 错误
- jquery - jQueryUI 在按钮上切换缩放效果
- android - 图像未从 SQLite 数据库更新
- apache-camel - 骆驼油门属性不起作用
- php - 购物车通知提醒链接到 Woocommerce 中的结帐
- jquery - 如何使用 jQuery 更改 css 属性名称?