有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java NumberFormat为某些地区的货币显示错误的十进制标记格式

对于某些地区,如es CO,我认为货币的numberformat十进制标记不正确:

 NumberFormat numberFormat =
 NumberFormat.getCurrencyInstance(new Locale("es", "CO"));
 numberFormat.setCurrency(Currency.getInstance("COP"));

 String currencyString = numberFormat.format(164900.12);
 System.out.println(currencyString);

对于这一点,我得到的结果是164.900,21,而当我签入像:http://www.xe.com/currencyconverter/convert这样的站点时 我从另一个方向得到它,即164900.21 这是NumberFormat类的问题还是我做错了什么


共 (1) 个答案

  1. # 1 楼答案

    请检查Locale类的构造函数,它首先排除语言,然后排除国家代码

     public Locale(String language, String country) {
        this(language, country, "");
     }
    

    像这样更改代码,您将得到这样的输出“COP 164900.12”

      NumberFormat numberFormat = NumberFormat.getCurrencyInstance(new Locale(
                    "CO", "es"));