Home  >  Article  >  Java  >  How to Format Indian Rupees (INR) in the Indian Numbering System?

How to Format Indian Rupees (INR) in the Indian Numbering System?

DDD
DDDOriginal
2024-10-25 08:32:28957browse

How to Format Indian Rupees (INR) in the Indian Numbering System?

Displaying Currency in Indian Numbering Format

Question:

How can I format the Indian Rupee currency (INR) in the Indian numbering system, where numbers are separated by commas after two digits, except for the last set, which is in thousands?

Answer:

Unfortunately, Java SE's standard DecimalFormat does not support variable-width grouping, making it impossible to format numbers according to the Indian numbering system.

However, ICU4J (International Components for Unicode) provides a NumberFormat class that supports this format:

<code class="java">Format format = com.ibm.icu.text.NumberFormat.getCurrencyInstance(new Locale("en", "in"));
System.out.println(format.format(new BigDecimal("100000000")));</code>

Output:

Rs 10,00,00,000.00

Note that the Android version of java.text.DecimalFormat class is implemented using ICU under the hood and supports the variable-width grouping feature as well.

The above is the detailed content of How to Format Indian Rupees (INR) in the Indian Numbering System?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn