support new Indian currency symbol in java

一曲冷凌霜 提交于 2019-12-03 15:47:02
Aaron

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.

https://www.karnataka.gov.in/Documents/Rupee_Foradian.ttf copy this font in windows fonts folder(in RUN ->type fonts).

then Font ProMed_Font=new Font("Rupee Foradian",Font.PLAIN,10); set above font to label

example:label.settext("100"+"`") output will be 100+rupee symblol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!