支持java中的新印度货币符号 [英] support new Indian currency symbol in java
问题描述
如何使用java来格式化具有新印度货币符号(₹)的数字。如果有任何解决方法让我们共享。
how to format a number with new Indian currency symbol(₹) using java.if there is any workaround let us share .
推荐答案
在Java正确支持新字符之前,您可以使用其unicode值手动指定货币符号。
Until Java properly supports the new character you can manually specify the currency symbol using its unicode value.
印度货币符号的Unicode为 U + 20B9
The Unicode for the Indian currency symbol is U+20B9
因此要将此字符插入java字符串,请将其指定为 \ u20B9
而不是默认的DecimalFormat货币值 \ u00A4
So to insert this character into a java string you specify it as \u20B9
instead of the default DecimalFormat currency value of \u00A4
例如:
DecimalFormat formatter = new DecimalFormat("\u20B9 000");
不幸的是,这会硬编码输出以始终显示卢比符号。如果您需要支持多个语言环境,可以检查user.country系统属性。
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");
此外,用于显示此字符串的组件必须具有包含货币符号的字体。窗口7上的Arial确实有,但许多其他人没有。
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.
这篇关于支持java中的新印度货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!