If the locale only specifies a language rather than a language and a country (such as * {@code Locale.JAPANESE} or {new Locale("en", "")} rather than {@code Locale.JAPAN} or * {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. */ public String getSymbol(Locale locale) { if (locale == null) { throw new NullPointerException("locale == null"); } // Check the locale first, in case the locale has the same currency. LocaleData localeData = LocaleData.get(locale); if (localeData.internationalCurrencySymbol.equals(currencyCode)) { return localeData.currencySymbol; } // Try ICU, and fall back to the currency code if ICU has nothing. String symbol = ICU.getCurrencySymbol(locale, currencyCode); return symbol != null ? symbol : currencyCode; } /** * 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. */ public int getDefaultFractionDigits() { // In some places the code XXX is used as the fall back currency. // The RI returns -1, but ICU defaults to 2 for unknown currencies. if (currencyCode.equals("XXX")) { return -1; } return ICU.getCurrencyFractionDigits(currencyCode); } /** * Returns this currency's ISO 4217 currency code. */ @Override public String toString() { return currencyCode; } private Object readResolve() { return getInstance(currencyCode); } }