ICU4j - How to override the currency symbol or add customized currency with Numberformatter

344 Views Asked by At

I want to override the currency symbol. For example, ICU only returns BGN 0.67 with currencyCode BGN no matter which options I use (Narrow, Short, and VARIANT in here) for en locale, but I would like to get лв 0.67. We also have other use cases to override the currency symbol.

com.ibm.icu.util.Currency doesn't provide any set functions to do the override. When Numberformatter appends the currency symbol to a number, it calls getName method to get currency symbol in Currency.java

public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat) {
  ...
  CurrencyDisplayNames names = CurrencyDisplayNames.getInstance(locale);
  switch (nameStyle) {
    case SYMBOL_NAME:
      return names.getSymbol(subType);
  ...
  }
  ...
}

CurrencyDisplayNames has predefined data, and doesn't provide any method to do the override.

I found Numberformat can override the currency symbol through Numberformat.getCurrencyInstance(), but ICU suggests the new users to use Numberformatter, so how do I do the symbol override, or other override like put dollar sign on the right of the number for a certain locale? (Most of the output ICU formats are good to us, but we want to customize for a currency under a certain locale)

0

There are 0 best solutions below