How do I get the currency symbol of a currency as

2019-04-11 16:24发布

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条回答
劫难
2楼-- · 2019-04-11 16:59

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

查看更多
登录 后发表回答