Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

support new Indian currency symbol in java

how to format a number with new Indian currency symbol(₹) using java.if there is any workaround let us share .

like image 275
user872448 Avatar asked Oct 07 '22 08:10

user872448


1 Answers

Until Java properly supports the new character you can manually specify the currency symbol using its unicode value.

The Unicode for the Indian currency symbol is U+20B9

So to insert this character into a java string you specify it as \u20B9 instead of the default DecimalFormat currency value of \u00A4

For example:

DecimalFormat formatter = new DecimalFormat("\u20B9 000");

Unfortunately this will hard code your output to always display the rupee symbol. If you need to support multiple locales you can check the user.country system property.

boolean iAmInIndia = "IN".equals(System.getProperty("user.country"));
DecimalFormat formatter = iAmInIndia ? new DecimalFormat("\u20B9 000") : new DecimalFormat("\u00A4 000");

Also, the component you are using to display this string must have a font which contains the currency symbol. Arial on Window 7 does, however many others don't.

like image 182
Aaron Avatar answered Oct 13 '22 11:10

Aaron