public class Currency extends MeasureUnit
Note: This class deliberately resembles java.util.Currency but it has a completely independent implementation, and adds features not present in the JDK.
Modifier and Type | Class and Description |
---|---|
static class |
Currency.CurrencyStringInfo
Deprecated.
This API is ICU internal only.
|
static class |
Currency.CurrencyUsage
Currency Usage used for Decimal Format
|
MeasureUnit.Complexity, MeasureUnit.Factory, MeasureUnit.MeasurePrefix
Modifier and Type | Field and Description |
---|---|
static int |
FORMAL_SYMBOL_NAME
Selector for getName() indicating the formal currency symbol.
|
static int |
LONG_NAME
Selector for getName() indicating the long name for a
currency, such as "US Dollar" for USD.
|
static int |
NARROW_SYMBOL_NAME
Selector for getName() indicating the narrow currency symbol.
|
static 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".
|
static int |
SYMBOL_NAME
Selector for getName() indicating a symbolic name for a
currency, such as "$" for USD.
|
static int |
VARIANT_SYMBOL_NAME
Selector for getName() indicating the variant currency symbol.
|
ACRE, ACRE_FOOT, AMPERE, ARC_MINUTE, ARC_SECOND, ASTRONOMICAL_UNIT, ATMOSPHERE, BAR, BARREL, BEAUFORT, BIT, BRITISH_THERMAL_UNIT, BUSHEL, BYTE, CALORIE, CANDELA, CARAT, CELSIUS, CENTILITER, CENTIMETER, CENTURY, CUBIC_CENTIMETER, CUBIC_FOOT, CUBIC_INCH, CUBIC_KILOMETER, CUBIC_METER, CUBIC_MILE, CUBIC_YARD, CUP, CUP_METRIC, DALTON, DAY, DAY_PERSON, DECADE, DECILITER, DECIMETER, DEGREE, DESSERT_SPOON, DESSERT_SPOON_IMPERIAL, DOT, DOT_PER_CENTIMETER, DOT_PER_INCH, DRAM, DROP, DUNAM, EARTH_MASS, EARTH_RADIUS, ELECTRONVOLT, EM, FAHRENHEIT, FATHOM, FLUID_OUNCE, FLUID_OUNCE_IMPERIAL, FOODCALORIE, FOOT, FURLONG, G_FORCE, GALLON, GALLON_IMPERIAL, GASOLINE_ENERGY_DENSITY, GENERIC_TEMPERATURE, GIGABIT, GIGABYTE, GIGAHERTZ, GIGAWATT, GRAIN, GRAM, HECTARE, HECTOLITER, HECTOPASCAL, HERTZ, HORSEPOWER, HOUR, INCH, INCH_HG, ITEM, JIGGER, JOULE, KARAT, KELVIN, KILOBIT, KILOBYTE, KILOCALORIE, KILOGRAM, KILOHERTZ, KILOJOULE, KILOMETER, KILOMETER_PER_HOUR, KILOPASCAL, KILOWATT, KILOWATT_HOUR, KILOWATT_HOUR_PER_100_KILOMETER, KNOT, LIGHT_SPEED, LIGHT_YEAR, LITER, LITER_PER_100KILOMETERS, LITER_PER_KILOMETER, LUMEN, LUX, MEGABIT, MEGABYTE, MEGAHERTZ, MEGALITER, MEGAPASCAL, MEGAPIXEL, MEGAWATT, METER, METER_PER_SECOND, METER_PER_SECOND_SQUARED, METRIC_TON, MICROGRAM, MICROMETER, MICROSECOND, MILE, MILE_PER_GALLON, MILE_PER_GALLON_IMPERIAL, MILE_PER_HOUR, MILE_SCANDINAVIAN, MILLIAMPERE, MILLIBAR, MILLIGRAM, MILLIGRAM_OFGLUCOSE_PER_DECILITER, MILLIGRAM_PER_DECILITER, MILLILITER, MILLIMETER, MILLIMETER_OF_MERCURY, MILLIMOLE_PER_LITER, MILLISECOND, MILLIWATT, MINUTE, MOLE, MONTH, MONTH_PERSON, NANOMETER, NANOSECOND, NAUTICAL_MILE, NEWTON, NEWTON_METER, NIGHT, OHM, OUNCE, OUNCE_TROY, PARSEC, PART_PER_MILLION, PASCAL, PERCENT, PERMILLE, PERMYRIAD, PETABYTE, PICOMETER, PINCH, PINT, PINT_METRIC, PIXEL, PIXEL_PER_CENTIMETER, PIXEL_PER_INCH, POINT, POUND, POUND_FOOT, POUND_FORCE, POUND_PER_SQUARE_INCH, QUART, QUART_IMPERIAL, QUARTER, RADIAN, REVOLUTION_ANGLE, SECOND, SOLAR_LUMINOSITY, SOLAR_MASS, SOLAR_RADIUS, SQUARE_CENTIMETER, SQUARE_FOOT, SQUARE_INCH, SQUARE_KILOMETER, SQUARE_METER, SQUARE_MILE, SQUARE_YARD, STONE, subType, TABLESPOON, TEASPOON, TERABIT, TERABYTE, THERM_US, TON, TONNE, type, VOLT, WATT, WEEK, WEEK_PERSON, YARD, YEAR, YEAR_PERSON
Modifier | Constructor and Description |
---|---|
protected |
Currency(String theISOCode)
Constructs a currency object for the given ISO 4217 3-letter
code.
|
Modifier and Type | Method and Description |
---|---|
static Currency |
fromJavaCurrency(Currency currency)
Returns a Currency object based on the currency represented by the given java.util.Currency.
|
static Set<Currency> |
getAvailableCurrencies()
Returns the set of available currencies.
|
static String[] |
getAvailableCurrencyCodes(Locale loc,
Date d)
Returns an array of Strings which contain the currency
identifiers that are valid for the given
Locale on the
given date. |
static String[] |
getAvailableCurrencyCodes(ULocale loc,
Date d)
Returns an array of Strings which contain the currency
identifiers that are valid for the given locale on the
given date.
|
static Locale[] |
getAvailableLocales()
Return an array of the locales for which a currency
is defined.
|
static ULocale[] |
getAvailableULocales()
Return an array of the ulocales for which a currency
is defined.
|
String |
getCurrencyCode()
Returns the ISO 4217 3-letter code for this currency object.
|
int |
getDefaultFractionDigits()
Returns the number of the number of fraction digits that should
be displayed for this currency.
|
int |
getDefaultFractionDigits(Currency.CurrencyUsage Usage)
Returns the number of the number of fraction digits that should
be displayed for this currency with Usage.
|
String |
getDisplayName()
Returns the display name for this currency in the default locale.
|
String |
getDisplayName(Locale locale)
Returns the display name for this currency in the given locale.
|
static Currency |
getInstance(Locale locale)
Returns a currency object for the default currency in the given
locale.
|
static Currency |
getInstance(String theISOCode)
Returns a currency object given an ISO 4217 3-letter code.
|
static Currency |
getInstance(ULocale locale)
Returns a currency object for the default currency in the given
locale.
|
static String[] |
getKeywordValuesForLocale(String key,
ULocale locale,
boolean commonlyUsed)
Given a key and a locale, returns an array of values for the key for which data
exists.
|
String |
getName(Locale locale,
int nameStyle,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
String |
getName(Locale locale,
int nameStyle,
String pluralCount,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the given locale.
|
String |
getName(ULocale locale,
int nameStyle,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
String |
getName(ULocale locale,
int nameStyle,
String pluralCount,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
int |
getNumericCode()
Returns the ISO 4217 numeric code for this currency object.
|
static com.ibm.icu.impl.TextTrieMap<Currency.CurrencyStringInfo> |
getParsingTrie(ULocale locale,
int type)
Deprecated.
This API is ICU internal only.
|
double |
getRoundingIncrement()
Returns the rounding increment for this currency, or 0.0 if no
rounding is done by this currency.
|
double |
getRoundingIncrement(Currency.CurrencyUsage Usage)
Returns the rounding increment for this currency, or 0.0 if no
rounding is done by this currency with the Usage.
|
String |
getSymbol()
Convenience and compatibility override of getName that
requests the symbol name for the default
DISPLAY locale. |
String |
getSymbol(Locale loc)
Convenience and compatibility override of getName that
requests the symbol name.
|
String |
getSymbol(ULocale uloc)
Convenience and compatibility override of getName that
requests the symbol name.
|
static boolean |
isAvailable(String code,
Date from,
Date to)
Queries if the given ISO 4217 3-letter code is available on the specified date range.
|
static String |
parse(ULocale locale,
String text,
int type,
ParsePosition pos)
Deprecated.
This API is ICU internal only.
|
static Object |
registerInstance(Currency currency,
ULocale locale)
Registers a new currency for the provided locale.
|
Currency |
toJavaCurrency()
Returns a java.util.Currency object based on the currency represented by this Currency.
|
String |
toString()
Returns the ISO 4217 code for this currency.
|
static boolean |
unregister(Object registryKey)
Unregister the currency associated with this key (obtained from
registerInstance).
|
addUnit, equals, findBySubType, forIdentifier, fromMeasureUnitImpl, getAvailable, getAvailable, getAvailableTypes, getComplexity, getCopyOfMeasureUnitImpl, getDimensionality, getIdentifier, getPrefix, getSubtype, getType, hashCode, internalGetInstance, product, reciprocal, splitToSingleUnits, withDimensionality, withPrefix
public static final int SYMBOL_NAME
public static final int LONG_NAME
public static final int PLURAL_LONG_NAME
public static final int NARROW_SYMBOL_NAME
The narrow currency symbol is similar to the regular currency symbol, but it always takes the shortest form; for example, "$" instead of "US$" for USD in en-CA.
public static final int FORMAL_SYMBOL_NAME
The formal currency symbol is similar to the regular currency symbol, but it always takes the form used in formal settings such as banking; for example, "NT$" instead of "$" for TWD in zh-TW.
public static final int VARIANT_SYMBOL_NAME
The variant symbol for a currency is an alternative symbol that is not necessarily as widely used as the regular symbol.
protected Currency(String theISOCode)
theISOCode
- The iso code used to construct the currency.public static Currency getInstance(Locale locale)
locale
- the localepublic static Currency getInstance(ULocale locale)
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d)
loc
- the locale for which to retrieve currency codes.d
- the date for which to retrieve currency codes for the given locale.public static String[] getAvailableCurrencyCodes(Locale loc, Date d)
Locale
on the
given date. If there are no such identifiers, returns null.
Returned identifiers are in preference order.loc
- the Locale
for which to retrieve currency codes.d
- the date for which to retrieve currency codes for the given locale.public static Set<Currency> getAvailableCurrencies()
public static Currency getInstance(String theISOCode)
theISOCode
- the iso codeNullPointerException
- if theISOCode
is null.IllegalArgumentException
- if theISOCode
is not a
3-letter alpha code.public static Currency fromJavaCurrency(Currency currency)
currency
- The Java currency object to convert.public Currency toJavaCurrency()
public static Object registerInstance(Currency currency, ULocale locale)
Because ICU may choose to cache Currency objects internally, this must be called at application startup, prior to any calls to Currency.getInstance to avoid undefined behavior.
currency
- the currency to registerlocale
- the ulocale under which to register the currencyunregister(java.lang.Object)
public static boolean unregister(Object registryKey)
registryKey
- the registry key returned from registerInstanceregisterInstance(com.ibm.icu.util.Currency, com.ibm.icu.util.ULocale)
public static Locale[] getAvailableLocales()
public static ULocale[] getAvailableULocales()
public static final String[] getKeywordValuesForLocale(String key, ULocale locale, boolean commonlyUsed)
The only supported key is "currency", other values return an empty array.
Currency information is based on the region of the locale. If the locale does not
indicate a region, ULocale.addLikelySubtags(ULocale)
is used to infer a region,
except for the 'und' locale.
If commonlyUsed is true, only the currencies known to be in use as of the current date are returned. When there are more than one, these are returned in preference order (typically, this occurs when a country is transitioning to a new currency, and the newer currency is preferred), see Unicode TR#35 Sec. C1. If commonlyUsed is false, all currencies ever used in any locale are returned, in no particular order.
key
- key whose values to look up. the only recognized key is "currency"locale
- the localecommonlyUsed
- if true, return only values that are currently used in the locale.
Otherwise returns all values.public String getCurrencyCode()
public int getNumericCode()
Note: If the ISO 4217 numeric code is not assigned for the currency or the currency is unknown, this method returns 0.
public String getSymbol()
DISPLAY
locale.getName(java.util.Locale, int, boolean[])
,
ULocale.Category.DISPLAY
public String getSymbol(Locale loc)
loc
- the Locale for the symbolgetName(java.util.Locale, int, boolean[])
public String getSymbol(ULocale uloc)
uloc
- the ULocale for the symbolgetName(java.util.Locale, int, boolean[])
public String getName(Locale locale, int nameStyle, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to return.
The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME,
or LONG_NAME. Otherwise, throw IllegalArgumentException.isChoiceFormat
- 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 supportedpublic String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to return.
The nameStyle should be SYMBOL_NAME, NARROW_SYMBOL_NAME,
or LONG_NAME. Otherwise, throw IllegalArgumentException.isChoiceFormat
- 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 supportedIllegalArgumentException
- if the nameStyle is not SYMBOL_NAME
or LONG_NAME.getName(ULocale, int, String, boolean[])
public String getName(Locale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to returnpluralCount
- plural count string for this localeisChoiceFormat
- 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 supportedpublic String getName(ULocale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to returnpluralCount
- plural count string for this localeisChoiceFormat
- 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 supportedIllegalArgumentException
- if the nameStyle is not SYMBOL_NAME,
LONG_NAME, or PLURAL_LONG_NAME.public String getDisplayName()
Note: This method is a convenience equivalent for
Currency.getDisplayName()
and is equivalent to
getName(Locale.getDefault(), LONG_NAME, null)
.
getDisplayName(Locale)
,
getName(Locale, int, boolean[])
public String getDisplayName(Locale locale)
Note: This method is a convenience equivalent for
Currency.getDisplayName(java.util.Locale)
and is equivalent
to getName(locale, LONG_NAME, null)
.
locale
- locale in which to display currencygetDisplayName(Locale)
,
getName(Locale, int, boolean[])
@Deprecated public static String parse(ULocale locale, String text, int type, ParsePosition pos)
locale
- the locale of the display names to matchtext
- the text to parsetype
- parse against currency type: LONG_NAME only or notpos
- 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.@Deprecated public static com.ibm.icu.impl.TextTrieMap<Currency.CurrencyStringInfo> getParsingTrie(ULocale locale, int type)
public int getDefaultFractionDigits()
public int getDefaultFractionDigits(Currency.CurrencyUsage Usage)
Usage
- the usage of currency(Standard or Cash)public double getRoundingIncrement()
public double getRoundingIncrement(Currency.CurrencyUsage Usage)
Usage
- the usage of currency(Standard or Cash)public String toString()
toString
in class MeasureUnit
public static boolean isAvailable(String code, Date from, Date to)
Note: For checking availability of a currency on a specific date, specify the date on both from
and
to
. When both from
and to
are null, this method checks if the specified
currency is available all time.
code
- The ISO 4217 3-letter code.from
- The lower bound of the date range, inclusive. When from
is null, check the availability
of the currency any date before to
to
- The upper bound of the date range, inclusive. When to
is null, check the availability of
the currency any date after from
IllegalArgumentException
- when to
is before from
.Copyright © 2016 Unicode, Inc. and others.