简体   繁体   English

不能在数字格式中使用特定的语言环境

[英]Can't use specific Locales in Numberformat

I just want to use danish as the locale when getting a currency numberformat ( where it says French now ) but no locale "code" can be used for it.我只想在获取货币数字格式时使用丹麦语作为语言环境(现在它说的是法语),但不能使用语言环境“代码”。

NumberFormat.getCurrencyInstance(Locale.FRENCH).format(pay);

When I check out the getAvailableLocales() method I get several that mention DK : da_DK_#Latn , da_DK , en_DK , fo_DK but the locale code just appears red in the code and the IDE says "Rename reference" .当我查看getAvailableLocales()方法时,我得到了几个提到DK的方法: da_DK_#Latnda_DKen_DKfo_DK ,但语言环境代码在代码中显示为红色,IDE 显示"Rename reference"

Only "big" languages show up such as french and can be used.只有“大”语言出现,例如法语,并且可以使用。

I don't know how to use a locale that isn't one of the big languages that automatically pop up as suggestions when you write the function.当您编写 function 时,我不知道如何使用不是自动弹出建议的主要语言之一的语言环境。

Only "big" languages show up such as french and can be used只有“大”语言出现,例如法语,可以使用

There is no constant in the Locale class for the locale that you are looking for, but you can instantiate it using one of the constructors defined by this class. Locale class 中没有您要查找的区域设置的常量,但您可以使用此 class 定义的构造函数之一实例化它。

To get the proper formatting for the currency, need a constructor that expects two string arguments: language and country codes.要获得正确的货币格式,需要一个需要两个字符串 arguments 的构造函数:语言和国家代码。

Locale locale = new Locale("da", "DK");
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);
System.out.println(currencyFormat.format(1000));

Output Output

1.000,00 kr.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用DateFormat和NumberFormat为几个不同的语言环境输出相同的日期,数字,价格和百分比? - How to use DateFormat and NumberFormat to output the same date, number, price and percentage for a few different Locales? NumberFormat显示某些语言环境的货币错误的小数点格式 - NumberFormat showing wrong decimal mark format for currencies for some locales 我怎样才能让NumberFormat使用一种货币,但使用小数美分/便士? - How can I get NumberFormat to use a currency but with fractional cents/pennies? 使用NumberFormat或DecimalFormat - Use NumberFormat or DecimalFormat Java 如何将 groupingSize() 与 NumberFormat 一起使用 - Java How to use groupingSize() with NumberFormat 无法在Mapbox LocationEngine中使用特定方法 - Can't use specific methods in Mapbox LocationEngine NumberFormat.getCurrencyInstance() 不返回语言环境中国和法国的货币符号 (jdk-1.8) - NumberFormat.getCurrencyInstance() not returning currency symbol for Locales CHINA and FRANCE (jdk-1.8) 如何在 Java 中使用 NumberFormat 进行自定义货币格式? - How to use NumberFormat in Java for custom currency formatting? 仅在 JVM 中使用 Android ICU NumberFormat - Use Android ICU NumberFormat with only the JVM NumberFormat不会因2个十进制分隔符而崩溃 - NumberFormat doesn't crash with 2 decimal separators
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM