Home > Java > javaTutorial > body text

How to Format Currency in Indian Numbering System Using ICU4J?

Barbara Streisand
Release: 2024-10-25 01:46:30
Original
880 people have browsed it

How to Format Currency in Indian Numbering System Using ICU4J?

Formatting Currency in Indian Numbering Format

Formatting currency in Indian numbering format can be challenging, as it differs from standard Western notation. Typically, a value like 450500 is written as 4,50,500 in India. This article explores the nuances of Indian currency formatting and provides a suitable solution using ICU4J.

The Indian numbering system uses commas to separate digits in groups of two, except for the last group, which is separated by thousands. For example:

  • 1
  • 10
  • 100
  • 1,000
  • 10,000
  • 1,00,000
  • 10,00,000
  • 1,00,00,000
  • 10,00,00,000

Java's standard DecimalFormat class does not support variable-width groups, making it unsuitable for this task. However, the ICU4J NumberFormat class overcomes this limitation.

<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 outputs:

Rs 10,00,00,000.00
Copy after login

Note that the ICU4J NumberFormat class extends Format, not NumberFormat. In the Android version of DecimalFormat, this feature is supported as well, as it is implemented using ICU.

The above is the detailed content of How to Format Currency in Indian Numbering System Using ICU4J?. 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!