Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some currency signs missing in Java currency API

Tags:

java

currency

I'm writing some currency conversion code in Java and and using this API to build up an internal lookup table of currencies

final Locale[] locales = Locale.getAvailableLocales();
for (final Locale locale : locales) {
   final Currency currency = Currency.getInstance(locale);
   String sign = currency.getSymbol(locale)
   String code = currency.getCurrencyCode()
     /* do something with them */
}

I've two observations so far.

  1. This listing does not return a Rupee sign in the native script https://en.wikipedia.org/wiki/Indian_rupee_sign. It returns Rs. instead

  2. Similarly for the Russian Ruble, it returns руб instead of the Ruble sign in the native script https://en.wikipedia.org/wiki/Ruble_sign

Many international currencies have signs in the Latin script and native script. Java doesn't seem to be consistent in what it returns. Am I running into a limitation or is my API usage incorrect?

Thanks!

like image 648
Ranjit Iyer Avatar asked Mar 09 '17 17:03

Ranjit Iyer


1 Answers

I tested your code for Indian Rupee sign, and it seems to be working perfectly. The symbol is available for locale hi_IN

Rupees symbol for hi_IN locale

But for en_IN, 'Rs' symbol is available

Rs symbol for en_IN locale

Make sure you use right locale. :)

like image 92
Dave Ranjan Avatar answered Oct 13 '22 01:10

Dave Ranjan