Top Description Inners Fields Constructors Methods
com.ibm.icu.util

public Class Currency

extends MeasureUnit
Class Inheritance
Known Direct Subclasses
com.ibm.icu.impl.number.CustomSymbolCurrency
Imports
java.io.ObjectStreamException, java.lang.ref.SoftReference, java.text.ParsePosition, java.util.ArrayList, .Collections, .Date, .HashSet, .Iterator, .List, .Locale, .Map, .MissingResourceException, .Set, com.ibm.icu.impl.CacheBase, .ICUCache, .ICUData, .ICUDebug, .ICUResourceBundle, .SimpleCache, .SoftCache, .StaticUnicodeSets, .TextTrieMap, com.ibm.icu.text.CurrencyDisplayNames, .CurrencyMetaInfo, .CurrencyMetaInfo.CurrencyDigits, .CurrencyMetaInfo.CurrencyFilter, .UnicodeSet, com.ibm.icu.util.ULocale.Category

A class encapsulating a currency, as defined by ISO 4217. A Currency object can be created given a Locale or given an ISO 4217 code. Once created, the Currency object can return various data necessary to its proper display: The DecimalFormat class uses these data to display currencies.

Note

This class deliberately resembles java.util.Currency but it has a completely independent implementation, and adds features not present in the JDK.

Author
Alan Liu
ICU Status
Stable since ICU 2.2.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
Currency.CurrencyStringInfo

Deprecated This API is ICU internal only.
public static enum
Currency.CurrencyUsage

Currency Usage used for Decimal Format

pack-priv abstract static class

Field Summary

Modifier and TypeField and Description
private static SoftReference<Set<String>>
private static SoftReference<List<String>>
private static ICUCache<ULocale, List<TextTrieMap<Currency.CurrencyStringInfo>>>
private static final boolean
private static final String[]
public static final int
FORMAL_SYMBOL_NAME

Selector for getName() indicating the formal currency symbol.

private final String
isoCode

ISO 4217 3-letter code.

public static final int
LONG_NAME

Selector for getName() indicating the long name for a currency, such as "US Dollar" for USD.

public static final int
NARROW_SYMBOL_NAME

Selector for getName() indicating the narrow currency symbol.

public static final int
PLURAL_LONG_NAME

Selector for getName() indicating the plural long name for a currency, such as "US dollar" for USD in "1 US dollar", and "US dollars" for USD in "2 US dollars".

private static final int[]
private static final CacheBase<String, Currency, Void>
private static final long
private static Currency.ServiceShim
public static final int
SYMBOL_NAME

Selector for getName() indicating a symbolic name for a currency, such as "$" for USD.

private static final ULocale
public static final int
VARIANT_SYMBOL_NAME

Selector for getName() indicating the variant currency symbol.

Inherited from com.ibm.icu.util.MeasureUnit:
ACREACRE_FOOTAMPEREARC_MINUTEARC_SECONDASCIIASCII_HYPHEN_DIGITSASTRONOMICAL_UNITATMOSPHEREBARBARRELBEAUFORTBITBRITISH_THERMAL_UNITBUSHELBYTECALORIECANDELACARATCELSIUSCENTILITERCENTIMETERCENTURYCUBIC_CENTIMETERCUBIC_FOOTCUBIC_INCHCUBIC_KILOMETERCUBIC_METERCUBIC_MILECUBIC_YARDCUPCUP_METRICCURRENCY_FACTORYDALTONDAYDAY_PERSONDECADEDECILITERDECIMETERDEGREEDESSERT_SPOONDESSERT_SPOON_IMPERIALDOTDOT_PER_CENTIMETERDOT_PER_INCHDRAMDROPDUNAMEARTH_MASSEARTH_RADIUSELECTRONVOLTEMFAHRENHEITFATHOMFLUID_OUNCEFLUID_OUNCE_IMPERIALFOODCALORIEFOOTFURLONGG_FORCEGALLONGALLON_IMPERIALGASOLINE_ENERGY_DENSITYGENERIC_TEMPERATUREGIGABITGIGABYTEGIGAHERTZGIGAWATTGRAINGRAMHECTAREHECTOLITERHECTOPASCALHERTZHORSEPOWERHOURINCHINCH_HGITEMJIGGERJOULEKARATKELVINKILOBITKILOBYTEKILOCALORIEKILOGRAMKILOHERTZKILOJOULEKILOMETERKILOMETER_PER_HOURKILOPASCALKILOWATTKILOWATT_HOURKILOWATT_HOUR_PER_100_KILOMETERKNOTLIGHT_YEARLITERLITER_PER_100KILOMETERSLITER_PER_KILOMETERLUMENLUXMEGABITMEGABYTEMEGAHERTZMEGALITERMEGAPASCALMEGAPIXELMEGAWATTMETERMETER_PER_SECONDMETER_PER_SECOND_SQUAREDMETRIC_TONMICROGRAMMICROMETERMICROSECONDMILEMILE_PER_GALLONMILE_PER_GALLON_IMPERIALMILE_PER_HOURMILE_SCANDINAVIANMILLIAMPEREMILLIBARMILLIGRAMMILLIGRAM_OFGLUCOSE_PER_DECILITERMILLIGRAM_PER_DECILITERMILLILITERMILLIMETERMILLIMETER_OF_MERCURYMILLIMOLE_PER_LITERMILLISECONDMILLIWATTMINUTEMOLEMONTHMONTH_PERSONNANOMETERNANOSECONDNAUTICAL_MILENEWTONNEWTON_METEROHMOUNCEOUNCE_TROYPARSECPART_PER_MILLIONPASCALPERCENTPERMILLEPERMYRIADPETABYTEPICOMETERPINCHPINTPINT_METRICPIXELPIXEL_PER_CENTIMETERPIXEL_PER_INCHPOINTPOUNDPOUND_FOOTPOUND_FORCEPOUND_PER_SQUARE_INCHQUARTQUART_IMPERIALQUARTERRADIANREVOLUTION_ANGLESECONDSOLAR_LUMINOSITYSOLAR_MASSSOLAR_RADIUSSQUARE_CENTIMETERSQUARE_FOOTSQUARE_INCHSQUARE_KILOMETERSQUARE_METERSQUARE_MILESQUARE_YARDSTONEsubTypeTABLESPOONTEASPOONTERABITTERABYTETHERM_USTIMEUNIT_FACTORYTONTONNEtypeVOLTWATTWEEKWEEK_PERSONYARDYEARYEAR_PERSON

Constructor Summary

AccessConstructor and Description
protected
Currency(String
The iso code used to construct the currency.
theISOCode
)

Constructs a currency object for the given ISO 4217 3-letter code.

Method Summary

Modifier and TypeMethod and Description
pack-priv static Currency
createCurrency(ULocale loc)

Instantiate a currency from resource data.

public static Currency

Returns:

An equivalent ICU currency object.
fromJavaCurrency
(Currency
The Java currency object to convert.
currency
)

Returns a Currency object based on the currency represented by the given java.util.Currency.

private static synchronized Set<String>
private static synchronized List<String>
public static Set<Currency>

Returns:

The set of available currencies. The returned set could be empty if there is no currency data available.
getAvailableCurrencies
()

Returns the set of available currencies.

public static String[]

Returns:

The array of ISO currency codes.
getAvailableCurrencyCodes
(ULocale
the locale for which to retrieve currency codes.
loc
,
Date
the date for which to retrieve currency codes for the given locale.
d
)

Returns an array of Strings which contain the currency identifiers that are valid for the given locale on the given date.

public static String[]

Returns:

The array of ISO currency codes.
getAvailableCurrencyCodes
(Locale
the java.util.Locale for which to retrieve currency codes.
loc
,
Date
the date for which to retrieve currency codes for the given locale.
d
)

Returns an array of Strings which contain the currency identifiers that are valid for the given java.util.Locale on the given date.

public static Locale[]

Returns:

an array of the available locales
getAvailableLocales
()

Return an array of the locales for which a currency is defined.

public static ULocale[]

Returns:

an array of the available ulocales
getAvailableULocales
()

Return an array of the ulocales for which a currency is defined.

public String
getCurrencyCode()

Returns the ISO 4217 3-letter code for this currency object.

private static List<TextTrieMap<Currency.CurrencyStringInfo>>
public int

Returns:

a non-negative number of fraction digits to be displayed
getDefaultFractionDigits
()

Returns the number of the number of fraction digits that should be displayed for this currency.

public int

Returns:

a non-negative number of fraction digits to be displayed
getDefaultFractionDigits
(Currency.CurrencyUsage
the usage of currency(Standard or Cash)
Usage
)

Returns the number of the number of fraction digits that should be displayed for this currency with Usage.

public String

Returns:

The display name of this currency
getDisplayName
()

Returns the display name for this currency in the default locale.

public String

Returns:

The display name of this currency for the specified locale
getDisplayName
(Locale
locale in which to display currency
locale
)

Returns the display name for this currency in the given locale.

public static Currency

Returns:

the currency object for this locale
getInstance
(Locale
the locale
locale
)

Returns a currency object for the default currency in the given locale.

public static Currency
getInstance(ULocale locale)

Returns a currency object for the default currency in the given locale.

public static Currency

Returns:

the currency for this iso code
getInstance
(String
the iso code
theISOCode
)

Returns a currency object given an ISO 4217 3-letter code.

public static final String[]

Returns:

an array of values for the given key and the locale. If there is no data, the array will be empty.
getKeywordValuesForLocale
(String
key whose values to look up. the only recognized key is "currency"
key
,
ULocale
the locale
locale
,
boolean
if true, return only values that are currently used in the locale. Otherwise returns all values.
commonlyUsed
)

Given a key and a locale, returns an array of values for the key for which data exists.

public String

Returns:

display string for this currency. If the resource data contains no entry for this currency, then the ISO 4217 code is returned.
getName
(Locale
locale in which to display currency
locale
,
int
selector for which kind of name to return. The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME, or LONG_NAME. Otherwise, throw IllegalArgumentException.
nameStyle
,
boolean[]
isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; display names are static strings; since ICU 4.4, ChoiceFormat patterns are no longer supported
isChoiceFormat
)

Returns the display name for the given currency in the given locale.

public String

Returns:

display string for this currency. If the resource data contains no entry for this currency, then the ISO 4217 code is returned.

getName
(ULocale
locale in which to display currency
locale
,
int
selector for which kind of name to return. The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME, or LONG_NAME. Otherwise, throw IllegalArgumentException.
nameStyle
,
boolean[]
isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; display names are static strings; since ICU 4.4, ChoiceFormat patterns are no longer supported
isChoiceFormat
)

Returns the display name for the given currency in the given locale.

public String

Returns:

display string for this currency. If the resource data contains no entry for this currency, then the ISO 4217 code is returned.
getName
(Locale
locale in which to display currency
locale
,
int
selector for which kind of name to return
nameStyle
,
String
plural count string for this locale
pluralCount
,
boolean[]
isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; display names are static strings; since ICU 4.4, ChoiceFormat patterns are no longer supported
isChoiceFormat
)

Returns the display name for the given currency in the given locale.

public String

Returns:

display string for this currency. If the resource data contains no entry for this currency, then the ISO 4217 code is returned.
getName
(ULocale
locale in which to display currency
locale
,
int
selector for which kind of name to return
nameStyle
,
String
plural count string for this locale
pluralCount
,
boolean[]
isChoiceFormat[0] is always set to false, or isChoiceFormat can be null; display names are static strings; since ICU 4.4, ChoiceFormat patterns are no longer supported
isChoiceFormat
)

Returns the display name for the given currency in the given locale.

public int

Returns:

The ISO 4217 numeric code of this currency.
getNumericCode
()

Returns the ISO 4217 numeric code for this currency object.

public static TextTrieMap<Currency.CurrencyStringInfo>
getParsingTrie(ULocale locale, int type)

Deprecated This API is ICU internal only.
public double

Returns:

the non-negative rounding increment, or 0.0 if none
getRoundingIncrement
()

Returns the rounding increment for this currency, or 0.0 if no rounding is done by this currency.

public double

Returns:

the non-negative rounding increment, or 0.0 if none
getRoundingIncrement
(Currency.CurrencyUsage
the usage of currency(Standard or Cash)
Usage
)

Returns the rounding increment for this currency, or 0.0 if no rounding is done by this currency with the Usage.

private static Currency.ServiceShim
public String
getSymbol()

Convenience and compatibility override of getName that requests the symbol name for the default DISPLAY locale.

public String
getSymbol(Locale
the Locale for the symbol
loc
)

Convenience and compatibility override of getName that requests the symbol name.

public String
getSymbol(ULocale
the ULocale for the symbol
uloc
)

Convenience and compatibility override of getName that requests the symbol name.

private static List<String>

Returns:

a list of tender currencies
getTenderCurrencies
(CurrencyMetaInfo.CurrencyFilter
the filter to apply to the tender currencies
filter
)

Returns the list of remaining tender currencies after a filter is applied.

private static boolean
public static boolean

Returns:

true if the given ISO 4217 3-letter code is supported on the specified date range.
isAvailable
(String
The ISO 4217 3-letter code.
code
,
Date
The lower bound of the date range, inclusive. When from is null, check the availability of the currency any date before to
from
,
Date
The upper bound of the date range, inclusive. When to is null, check the availability of the currency any date after from
to
)

Queries if the given ISO 4217 3-letter code is available on the specified date range.

private static Currency
public static String

Returns:

the ISO 4217 code, as a string, of the best match, or null if there is no match
parse
(ULocale
the locale of the display names to match
locale
,
String
the text to parse
text
,
int
parse against currency type: LONG_NAME only or not
type
,
ParsePosition
input-output position; on input, the position within text to match; must have 0 <= pos.getIndex() < text.length(); on output, the position after the last matched character. If the parse fails, the position in unchanged upon output.
pos
)

Deprecated This API is ICU internal only.
Attempt to parse the given string as a currency, either as a display name in the given locale, or as a 3-letter ISO 4217 code.
private Object
public static Object

Returns:

a registry key that can be used to unregister this currency
registerInstance
(Currency
the currency to register
currency
,
ULocale
the ulocale under which to register the currency
locale
)

Registers a new currency for the provided locale.

private static void
public Currency

Returns:

An equivalent Java currency object.
toJavaCurrency
()

Returns a java.util.Currency object based on the currency represented by this Currency.

public String
toString()

Overrides com.ibm.icu.util.MeasureUnit.toString.

Returns the ISO 4217 code for this currency.
public static boolean
unregister(Object
the registry key returned from registerInstance
registryKey
)

Unregister the currency associated with this key (obtained from registerInstance).

private Object
Inherited from com.ibm.icu.util.MeasureUnit:
addUnitequalsfindBySubTypeforIdentifierfromMeasureUnitImplgetAvailablegetAvailablegetAvailableTypesgetComplexitygetCopyOfMeasureUnitImplgetDimensionalitygetIdentifiergetPrefixgetSubtypegetTypehashCodeinternalGetInstanceproductreciprocalsplitToSingleUnitswithDimensionalitywithPrefix