Java – need space between currency symbol and amount

I am printing currency in INR format as follows:

NumberFormat fmt = NumberFormat.getCurrencyInstance();
fmt.setCurrency(Currency.getInstance("INR"));
fmt.format(30382.50);

Rs30382.50 is displayed, but in India it is written in rupees 30382.50 (see http://www.flipkart.com/ )How to solve the INR without hard coding?

Solution

This is a hacker, but in similar cases, 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 + " "));

All currencies I have to deal with involve two decimal places, so I can "0.00" for all currencies, but if you intend to use yen, you must adjust it There is a numberformat getCurrency(). getSymbol(); But it returns INR instead of Rs. so it cannot be used to obtain currency symbols

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>