java 货币区域设置-如何获取不同国家/地区的区域设置

0ejtzxu1  于 2023-05-21  发布在  Java
关注(0)|答案(2)|浏览(170)
public  double showinbrl(double amount, double rate) {
        double amountinbrl = amount * rate; 
        NumberFormat brl = NumberFormat.getCurrencyInstance(Locale.BRAZIL); 
        brl.format(amountinbrl);
        return amountinbrl;
    }

如何获得不同国家的区域设置。我找不到巴西的地方。

8yoxcaq7

8yoxcaq71#

试试这个:

NumberFormat brl = NumberFormat.getCurrencyInstance(Locale.forLanguageTag("pt_BR"));
ifmq2ha2

ifmq2ha22#

更新2023(Kotlin):
当我尝试使用“Locale.forLanguageTag(“pt_BR”)“时,它对我不起作用,它的格式不正确,并且显示了一个未知字符:

所以我在谷歌上搜索并使用了以下代码,它工作了:

val brl = NumberFormat.getCurrencyInstance(Locale("pt", "BR"))

相关问题