Background
I have an Android application where I want to format an integer value as a currency string depending on the ISO code and current locale. I'm using ICU library 1.8.1 for that.
For example, if I have a value 75 and the ISO code is "USD", I want to see "$75" on US locale, but "USD75" on French locale.
Problem
The problem is that I always see "USD75" even when I explicitly set the locale to US. I thought the problem is in my NumberFormat
currency instance, but then I tried to simply get the currency symbol and noticed that it's incorrect. For some reason getSymbol()
method always returns currency code.
public void test() {
Locale.setDefault(Locale.US);
String theISOCode = "USD"
Currency currency = Currency.getInstance(theISOCode);
currency.getCurrencyCode(); // "USD". This works as expected
currency.getSymbol(); // "USD". This looks weird.. Shouldn't it be "$"?
currency.getSymbol(Locale.US); // "USD". Same here, I expect it to be "$"
currency.getSymbol(ULocale.US); // still "USD"
}
I also checked this link: Java: Currency symbol based on ISO 4217 currency cod. It seems my app works a bit differently. Not sure if it's a bug in the library.
Question
It makes sense to me that currency.getSymbol()
returns "USD" if your locale is Locale.FRANCE
. But why does it return "USD" when my locale is Locale.US
? Would be great if I could find a solution without switching the library.
The issue turned out to be a bug in the library. After updating the version the issue got resolved. Thanks @Omid for looking into this.