Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currency.getSymbol() gives "US$" and "$" with different devices

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.

like image 374
Sandeep Avatar asked Sep 13 '25 07:09

Sandeep


1 Answers

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). 
like image 175
Johannes Kuhn Avatar answered Sep 15 '25 22:09

Johannes Kuhn