如何获得货币的货币符号,就像它在其中一个本地区域设置中出现一样? [英] How do I get the currency symbol of a currency as it would appear in one of its native locales?

查看:172
本文介绍了如何获得货币的货币符号,就像它在其中一个本地区域设置中出现一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Currency currency = Currency.getInstance(currencyCode);

如何获得货币的符号,就像它出现在其本地区域中的符号一样到默认语言环境?

How do I get the symbol of the currency as it would appear in one of its native locales as opposed to the default locale?

currency.getSymbol()将无效,因为它将基于默认值语言环境。
currency.getSymbol(区域设置区域设置)将无效,因为代码无法仅基于currencyCode派生正确的区域设置。

currency.getSymbol() won't work because that will be based of the default locale. currency.getSymbol(Locale locale) won't work because the code will not be able to derive a proper locale based purely on the currencyCode.

推荐答案

虽然我同意你的说法代码无法根据currencyCode派生出适当的语言环境 Currency.getInstance()也接受Locale作为参数。

While I agree with you when you said "the code will not be able to derive a proper locale based purely on the currencyCode", Currency.getInstance() also accepts a Locale as a parameter.

我认为这是你最好的选择。如果没有更多内容,我不确定如何从代码中的任何内容派生Locale,但可能,如果您能找到方法,则可以创建Locale对象,并使用它来获取Currency的实例宾语。它应该从那里顺利航行。

I think that this is going to be your best bet. Without more to go on, I'm not sure how you will derive the Locale from anything in your code, but presumably, if you can find a way, you can create a Locale object, and use it to grab an instance of a Currency object. It should be smooth sailing from there.

祝你好运!

参考文献:

http:// docs .oracle.com / javase / 7 / docs / api / java / util / Currency.html

http://docs.oracle.com/javase/1.5.0/docs/api/java/ util / Locale.html

这篇关于如何获得货币的货币符号,就像它在其中一个本地区域设置中出现一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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