Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add the new currency code to Java?

The Chinese currency has the ISO 4217 code CNY. Since free global trading in that currency is restricted though, there's a second 'offshore' currency equivalent, called CNH. Wikipedia has a bit of summary of this all.

CNH isn't in ISO 4217, but I'd like to be able to use it in my app without having to write my own Currency class. Presumably there's some kind of list somewhere inside the JVM install. How do I go about adding additional currency codes?

EDIT: See this question for dealing with this in Java 7

like image 771
sharakan Avatar asked Apr 02 '12 19:04

sharakan


People also ask

How do you create a currency object in Java?

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

What is the currency of Java?

Java Currency Class: getSymbol() MethodThe getSymbol() method is used to get the symbol of a given currency for the default DISPLAY locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$".


1 Answers

Looks like support for this was added with Java 7.

For earlier versions, you could use an equivalent Currency class of your own devising, or less happily, replace the default java.util.Currency class (or java.util.CurrencyData, which contains the raw data) in your classpath (whitepaper).

like image 83
Michael Brewer-Davis Avatar answered Sep 21 '22 17:09

Michael Brewer-Davis