While Initializing Currency, I set locale ad locale.US Currency.getInstance(Locale.US), but getSymbol() gives "US$" and "$ on different devices. getSymbol() gives "$" on samsung, but gives "US$" on moto. How to solve this.
From the javadoc of Currency.getSymbol()
Gets the symbol of this currency for the default
DISPLAY
locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.If the default
DISPLAY
locale contains "rg" (region override) Unicode extension, the symbol returned from this method reflects the value specified with that extension.This is equivalent to calling
getSymbol(Locale.getDefault(Locale.Category.DISPLAY))
.
This describes the reason why you sometimes see "US$" and sometimes just "$".
If you want to get reproducible results use
Currency.getInstance(Locale.US).getSymbol(Locale.US).