java.util.Currency.getCurrencyCode()
The method java.util.Currency.getCurrencyCode() gets the ISO 4217 currency code of this currency.
Method signature
The signature of the java.util.Currency.getCurrencyCode() method is as follows:
public String getCurrencyCode()
Parameters
The method takes no parameters.
Return value
Returns the ISO 4217 currency code of this currency.
Exceptions
The method throws no exceptions.
Example usage
In the following code we use java.util.Currency.getCurrencyCode():
package com.farenda.java.util; import java.util.Currency; import java.util.Locale; public class CurrencyCurrencyCode { public static void main(String[] args) { Locale locale = Locale.CHINA; Currency currency = Currency.getInstance(locale); //ISO 4217 code: System.out.println("Currency code: " + currency.getCurrencyCode()); currency = Currency.getInstance(Locale.CANADA_FRENCH); System.out.println("Currency code: " + currency.getCurrencyCode()); } }
The above code produces the following output:
Currency code: CNY Currency code: CAD