Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a text description of an ISO currency code in Java?

Tags:

java

currency

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

like image 387
brabster Avatar asked Sep 22 '09 08:09

brabster


People also ask

How do you write ISO currency?

The first two letters of the ISO 4217 three-letter code are the same as the code for the country name, and, where possible, the third letter corresponds to the first letter of the currency name. For example: The US dollar is represented as USD – the US coming from the ISO 3166 country code and the D for dollar.

Are all currency codes 3 letters?

The official ISO 4217 standard specifies three-letter ("Alpha-3") codes for currencies worldwide. The first two letters of these codes are usually identical with the two-letter ISO 3166-1 Alpha-2 country codes, which are well-known by internet users, as they are used for country domain suffixes.

How do you create a currency object in Java?

getInstance() : java. util. Currency. getInstance() method creates currency instance for Currency code.

What is the datatype for currency in Java?

1 Answer. Java has Currency class that represents the ISO 4217 currency codes. BigDecimal is the best type for representing currency decimal values.


2 Answers

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.

like image 106
Bombe Avatar answered Oct 13 '22 06:10

Bombe


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.

like image 35
ZZ Coder Avatar answered Oct 13 '22 05:10

ZZ Coder