Home > Java > javaTutorial > body text

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

Patricia Arquette
Release: 2024-10-25 05:57:02
Original
220 people have browsed it

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>
Copy after login

This code will produce the following output:

Rs 10,00,00,000.00
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!