Package java.util
Class Currency
- java.lang.Object
-
- java.util.Currency
-
- All Implemented Interfaces:
Serializable
public final class Currency extends Object implements Serializable
A currency corresponding to an ISO 4217 currency code such as "EUR" or "USD".- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Set<Currency>getAvailableCurrencies()Returns a set of all known currencies.StringgetCurrencyCode()Returns this currency's ISO 4217 currency code.intgetDefaultFractionDigits()Returns the default number of fraction digits for this currency.StringgetDisplayName()Equivalent togetDisplayName(Locale.getDefault()).StringgetDisplayName(Locale locale)Returns the localized name of this currency in the givenlocale.static CurrencygetInstance(String currencyCode)Returns theCurrencyinstance for the given ISO 4217 currency code.static CurrencygetInstance(Locale locale)Returns theCurrencyinstance for thisLocale's country.StringgetSymbol()Equivalent togetSymbol(Locale.getDefault()).StringgetSymbol(Locale locale)Returns the localized currency symbol for this currency inlocale.StringtoString()Returns this currency's ISO 4217 currency code.
-
-
-
Method Detail
-
getInstance
public static Currency getInstance(String currencyCode)
Returns theCurrencyinstance for the given ISO 4217 currency code.- Throws:
IllegalArgumentException- if the currency code is not a supported ISO 4217 currency code.
-
getInstance
public static Currency getInstance(Locale locale)
Returns theCurrencyinstance for thisLocale's country.- Throws:
IllegalArgumentException- if the locale's country is not a supported ISO 3166 country.
-
getAvailableCurrencies
public static Set<Currency> getAvailableCurrencies()
Returns a set of all known currencies.- Since:
- 1.7
-
getCurrencyCode
public String getCurrencyCode()
Returns this currency's ISO 4217 currency code.
-
getDisplayName
public String getDisplayName()
Equivalent togetDisplayName(Locale.getDefault()). See "Be wary of the default locale".- Since:
- 1.7
-
getDisplayName
public String getDisplayName(Locale locale)
Returns the localized name of this currency in the givenlocale. Returns the ISO 4217 currency code if no localized name is available.- Since:
- 1.7
-
getSymbol
public String getSymbol()
Equivalent togetSymbol(Locale.getDefault()). See "Be wary of the default locale".
-
getSymbol
public String getSymbol(Locale locale)
Returns the localized currency symbol for this currency inlocale. That is, given "USD" and Locale.US, you'd get "$", but given "USD" and a non-US locale, you'd get "US$".If the locale only specifies a language rather than a language and a country (such as
Locale.JAPANESEor {new Locale("en", "")} rather thanLocale.JAPANor {new Locale("en", "US")}), the ISO 4217 currency code is returned.If there is no locale-specific currency symbol, the ISO 4217 currency code is returned.
-
getDefaultFractionDigits
public int getDefaultFractionDigits()
Returns the default number of fraction digits for this currency. For instance, the default number of fraction digits for the US dollar is 2 because there are 100 US cents in a US dollar. For the Japanese Yen, the number is 0 because coins smaller than 1 Yen became invalid in 1953. In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.
-
-