java.util.Currency.getNumericCode()
Currencies are identified by their ISO 4217 currency codes. The method java.util.Currency.getNumericCode() returns the ISO 4217 numeric code of this currency.
The numeric code is useful when currency codes need to be understood in countries that don’t use Latin scripts and for computerized systems.
Method signature
The signature of the java.util.Currency.getNumericCode() method is as follows:
public int getNumericCode()
The method is available since Java 7.
Parameters
The method takes no parameters.
Return value
Returns the ISO 4217 numeric code of this currency.
Exceptions
The method throws no exceptions.
Example usage
In the following code we use Java.Util.Currency.getNumericCode():
package com.farenda.java.util; import java.util.Currency; import java.util.Locale; public class CurrencyGetNumericCode { public static void main(String[] args) { Locale locale = Locale.CHINA; Currency currency = Currency.getInstance(locale); System.out.printf("Numeric (ISO 4217) code of %s: %d%n", currency, currency.getNumericCode()); locale = Locale.US; currency = Currency.getInstance(locale); System.out.printf("Numeric (ISO 4217) code of %s: %d%n", currency, currency.getNumericCode()); } }
The above code produces the following output:
Numeric (ISO 4217) code of CNY: 156 Numeric (ISO 4217) code of USD: 840