【问题标题】:How to change NumberFormat from especific currency to a dollar currency如何将 NumberFormat 从特定货币更改为美元货币
【发布时间】:2014-02-18 13:49:02
【问题描述】:

我有这段代码

双倍价格 = rs.getDouble("价格");

NumberFormat nf= NumberFormat.getCurrencyInstance();

String formatedPrice = nf.format(price);

buff.append("(" + formatedPrice + ")");

当我运行代码时,一切正常,但货币设置为例如: (C800)。我想是因为我的国家有货币的“冒号”,但这是过去的事情,我们现在使用美元货币。那么如何更改货币以显示:(400 美元)而不是(C300)。非常感谢您的帮助。

【问题讨论】:

    标签: java money-format


    【解决方案1】:

    改用:

    NumberFormat nf= NumberFormat.getCurrencyInstance(Locale.US);
    

    【讨论】:

    • 感谢大家的回答,就像魅力一样。因为我是菜鸟,所以我不能给所有分数。
    • 哦,非常感谢你的建议,我不知道
    【解决方案2】:

    假设您使用的是美元,您可以使用NumberFormat.getCurrencyInstance(Locale.US)

    【讨论】:

      【解决方案3】:

      您可以将语言环境作为参数添加到 getCurrencyInstance:

      NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
      

      【讨论】:

        【解决方案4】:

        您可以将其默认为 $

        解决办法

            double price = rs.getDouble("price");
            NumberFormat nf= NumberFormat.getCurrencyInstance();
            nf.setMaximumFractionDigits(2);
                Currency currency = Currency.getInstance(Locale.US);
                nf.setCurrency(currency);
                String formatedPrice = nf.format(price);
                 System.out.println("( " + formatedPrice + ")");
        

        解决办法

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-06
          • 1970-01-01
          • 2011-05-05
          • 1970-01-01
          相关资源
          最近更新 更多