区域设置货币符号 [英] Locale Currency Symbol

查看:574
本文介绍了区域设置货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题得到了系统的默认货币符号。 我得到的货币符号是这样的:

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());

在系统语言是在英语(美国)右符号显示出来($ <$ C C $>)。 但是,当我选择的语言葡萄牙语(葡萄牙)返回这个符号¤

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 ¤.

有什么可以导致此?

推荐答案

这似乎是一个已知的问题(<一href="http://$c$c.google.com/p/android/issues/detail?id=38622">http://$c$c.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:

由于该问题是在符号,而不是货币code,我解决了这个问题,创建一个静态地图,其中的关键是的货币$ C $ç的和值是符号的。

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","$");
            (..)
        }
};

为了让所有(或几乎)codeS提供的语言环境的信息,你可以做这样的事情的货币:

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
  }
}

在创建映射与货币code 符号的你就必须是这样的:

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());

这篇关于区域设置货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆