[英]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_#Latn
、 da_DK
、 en_DK
、 fo_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.