获取没有Locale常量的国家/地区的货币格式 [英] Get the currency format for a country that does not have a Locale constant
本文介绍了获取没有Locale常量的国家/地区的货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得印度的货币格式,因此我需要印度的 Locale
对象。但是只有少数国家/地区有 Locale
常量(静态最终区域设置
),而印度不是一个为了获得美国和英国的货币符号,我可以执行以下操作:
public void displayCurrencySymbols(){
Currency currency = Currency.getInstance(Locale.US);
System.out.println(美国:+ currency.getSymbol());
currency = Currency.getInstance(Locale.UK);
System.out.println(英国:+ currency.getSymbol());
}
使用常量 Locale。美国
和 Locale.UK
。如果我想获得印度货币格式,我该怎么办?
解决方案
根据 JDK发行说明,您有区域代码 hi_IN
(印地语)和 en_IN
(英语)。
System.out.println(Currency.getInstance(new Locale(hi,IN))。getSymbol());
I want to get the currency format of India, so I need a Locale
object for India. But there exists only few a countries that have a Locale
constant (a static final Locale
), and India is not one of them.
To get the currency symbols for the US and UK, I can do the following:
public void displayCurrencySymbols() {
Currency currency = Currency.getInstance(Locale.US);
System.out.println("United States: " + currency.getSymbol());
currency = Currency.getInstance(Locale.UK);
System.out.println("United Kingdom: " + currency.getSymbol());
}
That uses the constants Locale.US
and Locale.UK
. If i want to get the Indian currency format, what can I do?
解决方案
According to the JDK release notes, you have locale codes hi_IN
(Hindi) and en_IN
(English).
System.out.println(Currency.getInstance(new Locale("hi", "IN")).getSymbol());
这篇关于获取没有Locale常量的国家/地区的货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文