需要货币符号和金额之间的空间 [英] need space between currency symbol and amount
问题描述
我正在尝试打印这样的INR格式货币:
I'm trying to print INR format currency like this:
NumberFormat fmt = NumberFormat.getCurrencyInstance();
fmt.setCurrency(Currency.getInstance("INR"));
fmt.format(30382.50);
显示 Rs30,382.50
,但在印度它写成卢比。 30,382.50
(参见 http://www.flipkart.com/ )
如何在没有硬编码的情况下解决INR?
shows Rs30,382.50
, but in India its written as Rs. 30,382.50
(see http://www.flipkart.com/)
how to solve without hardcoding for INR?
推荐答案
这有点像黑客但是在非常类似的情况下,我用了一些东西像这样
It's a bit of a hack but in a very similar situation, I used something like this
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
String currencySymbol = format.format(0.00).replace("0.00", "");
System.out.println(format.format(30382.50).replace(currencySymbol, currencySymbol + " "));
我必须处理的所有货币都涉及两位小数,所以我能够做到0.00
对于所有这些人,但如果你打算使用像日元这样的东西,这必须进行调整。有一个 NumberFormat.getCurrency()。getSymbol()
;但它返回 INR
而不是 Rs。
,因此不能用于获取货币符号。
all the currencies I had to deal with involved two decimal places so i was able to do "0.00"
for all of them but if you plan to use something like Japanese Yen, this has to be tweaked. There is a NumberFormat.getCurrency().getSymbol()
; but it returns INR
instead for Rs.
so that cannot be used for getting the currency symbol.
这篇关于需要货币符号和金额之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!