Locale Currency Symbol(语言环境货币符号)
问题描述
我在获取系统的默认货币符号时遇到了一些问题.我以这种方式获取货币符号:
I having some problems getting the default currency symbol of the system. I am getting the currency symbol this way:
Currency currency = Currency.getInstance(Locale.getDefault());
Log.v("TAG",currency.getSymbol());
当系统语言为英语(美国)
时,右侧的符号会显示($
).但是当我选择语言 Portuguese (Portugal)
它返回这个符号 ¤
.
When the system language is in English (United States)
the right symbol shows up ($
).
But when i choose the language Portuguese (Portugal)
it returns this symbol ¤
.
这是什么原因造成的?
推荐答案
这似乎是一个已知问题(http://code.google.com/p/android/issues/detail?id=38622.我通过这种方式得出了一个可能的解决方案:
This seems to be a known issue (http://code.google.com/p/android/issues/detail?id=38622. I came to a possible solution this way:
由于问题出在符号而不是货币代码中,我解决了这个问题,创建了一个静态Map
,其中键是 CurrencyCode,值是 符号.
Since the problem is in the Symbol and not the Currency code, i solved this problem creating a staticMap
where the key is the CurrencyCode and the value is the Symbol.
public static final Map<String, String> MYCURRENCIES = new HashMap<String, String>(){
{
put("EUR","€");
put("USD","$");
(..)
}
};
为了获取语言环境信息中可用的所有(或几乎)货币代码,您可以执行以下操作:
In order to get all (or almost) the currencies codes available in the locales information you can do something like this:
for (Locale ll: Locale.getAvailableLocales()){
try {
Currency a = Currency.getInstance(ll);
Log.v("MyCurrency",a.getCurrencyCode()+"#"+a.getSymbol());
}catch (Exception e){
// when the locale is not supported
}
}
使用 CurrencyCode 和 Symbol 创建地图后,您只需要这样:
After you created you Map with the CurrencyCode and Symbol you just have to something like this:
Currency currency = Currency.getInstance(Locale.getDefault());
String curSymbol = MYCURRENCIES.get(currency.getCurrencyCode());
这篇关于语言环境货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:语言环境货币符号


- 获取数字的最后一位 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01