Java Reference
In-Depth Information
The first getInstance call uses a Locale instance to retrieve a currency ob-
ject. The Java platform associates a default currency with the locale's region. In this
case, the default currency currently associated with the United States is the U.S. dollar:
Currency c1 = Currency.getInstance(Locale.US);
The second getInstance call uses a valid ISO 4217 currency code. The cur-
rency code for the U.S. dollar is USD :
Currency c2 = Currency.getInstance("USD");
Once you have a currency instance, you simply have to use that instance in your
formatter:
nf.setCurrency(c2);
This formatter now is configured to use the default locale's number format symbols
and patterns to format the number value, but it will display the targeted currency code
as part of the displayable text. This allows you to mix the default number format pat-
terns with other currency codes.
Note Currencies have both symbols and codes. A currency code always refers to the
three-letter ISO 4217 code. A currency symbol is often different from the code. For ex-
ample, the U.S. dollar has the code USD and the symbol $ . A currency formatter will
typically use a symbol when formatting a number in the default locale using the cur-
rency of that locale's region. However, when you explicitly change the currency of a
formatter, the formatter doesn't always have knowledge of a localized symbol for the
target currency. In that case, the format instance will often use the currency code in the
displayed text.
12-7.
Converting
Byte
Arrays
to
and
from Strings
Problem
Search WWH ::




Custom Search