问题
Is there a way to get a text description of the currency represented by a Currency object in Java?
i.e. I have AZM, I want Azerbaijan Manat
回答1:
You will have to set up your own mapping. Google or Stackoverflow questions will point to the ISO site
However you'll have to scrape the page as there seems to be no XML or text file as there is for country
回答2:
Such a mapping would again be Locale
-dependent… I think your best bet would be to take a long, hard look at ISO 4217 and create a Map
from currency code to currency name.
回答3:
It's not supported by Java but a few libraries can do this.
My number one choice would be ICU,
http://icu-project.org/apiref/icu4j/com/ibm/icu/util/Currency.html#getName%28java.util.Locale,%20int,%20boolean[]%29
This call can get you the name of a currency in multiple locales. ICU also supports all other i18n features not available in JRE. However, it's pretty big.
Another option is jPOS,
http://gl.jpos.org/
If you do anything with financial data, this is the de-facto standards. Watch for its license. Our lawyers didn't like it for some reason.
回答4:
Class java.util.Currency implements this since java 1.7.
Currency curr = Currency.getInstance("AZM");
System.out.println(curr.getCurrencyCode()); // AZM
System.out.println(curr.getNumericCode()); // 31
System.out.println(curr.getDisplayName()); // Azerbaijani Manat (1993-2006)
Unfortunatelly, this class is still far from usability... e.g. missing constructor from numericCode, some displayNames containings not event DisplayName, ...
回答5:
Not in the standard API. The data behind the Currency class is loaded from the package-private class java.util.CurrencyData
, and there's simply no text description present there. You can look at it if you have the source code installed with your JDK.
回答6:
openexchangerates.org
provides this info live online in machine-readable JSON
format:
http://openexchangerates.org/api/currencies.json
It returns information as simple as this:
{
"AED": "United Arab Emirates Dirham",
"AFN": "Afghan Afghani",
...
"ZMK": "Zambian Kwacha",
"ZWL": "Zimbabwean Dollar"
}
It's almost free but there are some terms and conditions. Here is the online documentation.
来源:https://stackoverflow.com/questions/1458912/can-i-get-a-text-description-of-an-iso-currency-code-in-java