"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Format Currency in Indian Numbering System Using ICU4J?

How to Format Currency in Indian Numbering System Using ICU4J?

Published on 2024-11-12
Browse:586

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.

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

This code outputs:

Rs 10,00,00,000.00

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3