How do I get the currency symbol of a currency as it would appear in one of its native locales?

為{幸葍}努か 提交于 2019-12-09 19:22:39

问题


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


回答1:


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.

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.

Good Luck!

References:

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



来源:https://stackoverflow.com/questions/9185793/how-do-i-get-the-currency-symbol-of-a-currency-as-it-would-appear-in-one-of-its

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!