Java:货币到语言环境的映射可能吗?

标签 java formatting currency

我在数据库中存储了一个与货币金额相关的值,例如 10.0。我还可以访问货币/货币代码。当我不知道语言环境时,如何使用 NumberFormat/DecimalFormat/(other?) 进行格式化?根据文档,它将选择一个不适用于外币的默认语言环境。

最佳答案

JasonTrue 是正确的,但您可以覆盖 NumberFormat 语言环境的货币:

NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
//the user may have selected a different currency than the default for their locale
Currency currency = Currency.getInstance("GBP");
numberFormat.setCurrency(currency);
numberFormat.format(amount);

关于Java:货币到语言环境的映射可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/758255/

相关文章:

python - 打印格式化的 numpy 数组

python - ndarray 行不显示每一行

wordpress - P文本添加到html文本中

mysql - 资金过期追踪

java - Char 到 Int,将 int 值更改回 char,然后添加到字符串

java - 为什么删除后刷新JTable不起作用

Java程序使用列表查找 'Lucky'从0到n的数字

java - 无法使用 Intent 启动新 Activity

c - 为什么我的程序会给我多余的输出? C程序

python - 确定字符串是否包含任何货币符号?