Home  >  Article  >  Java  >  How can I format Indian Rupee (INR) currency values in the Indian numbering system?

How can I format Indian Rupee (INR) currency values in the Indian numbering system?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-25 05:57:02202browse

How can I format Indian Rupee (INR) currency values in the Indian numbering system?

Formatting Currency in Indian Numbering Format

Question:

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

Answer:

Java's standard DecimalFormat class does not support variable-width grouping, so it cannot format values precisely as required.

Solution:

To correctly format INR values in the Indian numbering system, consider using the ICU4J NumberFormat class. Here's an example:

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

This code will produce the following output:

Rs 10,00,00,000.00

Additional Notes:

  • The Android version of java.text.DecimalFormat supports variable-width grouping.
  • Note that the ICU4J NumberFormat class extends the java.text.Format class, not the java.text.NumberFormat class.

The above is the detailed content of How can I format Indian Rupee (INR) currency values 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