Unfortunately on standard Java SE DecimalFormat doesn't support variable-width groups. So it won't ever format the values exactly as you want to:

If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

Most number formatting mechanisms in Java are based on that class and therefore inherit this flaw.

ICU4J (the Java version of the International Components for Unicode) provides a NumberFormat class that does support this formatting:

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

This code will produce this output:

Rs 10,00,00,000.00

Note: the com.ibm.icu.text.NumberFormat class does not extend the java.text.NumberFormat class (because it already extends an ICU-internal base class), it does however extend the java.text.Format class, which has the format(Object) method.

Note that the Android version of java.text.DecimalFormat class is implemented using ICU under the hood and does support the feature in the same way that the ICU class itself does (even though the summary incorrectly mentions that it's not supported).

Answer from Joachim Sauer on Stack Overflow
Top answer
1 of 16
102

Unfortunately on standard Java SE DecimalFormat doesn't support variable-width groups. So it won't ever format the values exactly as you want to:

If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

Most number formatting mechanisms in Java are based on that class and therefore inherit this flaw.

ICU4J (the Java version of the International Components for Unicode) provides a NumberFormat class that does support this formatting:

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

This code will produce this output:

Rs 10,00,00,000.00

Note: the com.ibm.icu.text.NumberFormat class does not extend the java.text.NumberFormat class (because it already extends an ICU-internal base class), it does however extend the java.text.Format class, which has the format(Object) method.

Note that the Android version of java.text.DecimalFormat class is implemented using ICU under the hood and does support the feature in the same way that the ICU class itself does (even though the summary incorrectly mentions that it's not supported).

2 of 16
30

With Android, this worked for me:

new DecimalFormat("##,##,##0").format(amount);

450500 gets formatted as 4,50,500

http://developer.android.com/reference/java/text/DecimalFormat.html - DecimalFormat supports two grouping sizes - the primary grouping size, and one used for all others.

🌐
HackerRank
hackerrank.com › challenges › java-currency-formatter › forum
Java Currency Formatter Discussions | Java | HackerRank
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); // US Locale NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US); // India Locale (custom, because no built-in Locale) Locale indiaLocale = new Locale("en", "IN"); NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale); // China Locale NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA); // France Locale NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE); System.out.println("US: " + us.format(payment)); System.out.println("India: " + india.format(payment)); System.out.println("China: " + china.format(payment)); System.out.println("France: " + france.format(payment)); }
🌐
Blogger
manishpaneri.blogspot.com › 2017 › 12 › java-currency-formatter-solution.html
Java Currency Formatter Solution
... On the first line, print US: u where is formatted for US currency. On the second line, print India: i where is formatted for Indian currency. On the third line, print China: c where is formatted for Chinese currency. On the fourth line, print France: f, where is formatted for French currency.
🌐
GitHub
github.com › kanika011 › Java-Hackerrank › blob › master › Java Currency Formatter.java
Java-Hackerrank/Java Currency Formatter.java at master · kanika011/Java-Hackerrank
Given a double-precision number, , denoting an amount of money, use the NumberFormat class' getCurrencyInstance method to convert into the US, Indian, Chinese, and French currency formats.
Author   kanika011
🌐
Stack Abuse
stackabuse.com › how-to-format-number-as-currency-string-in-java
How to Format Number as Currency String in Java
January 20, 2021 - In this guide, you will use Java to format a number into a currency string. We use Locale, Currency and NumberFormat objects.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-a-string-to-a-currency-format
Java Program to Convert a String to a Currency Format - GeeksforGeeks
July 23, 2025 - We use the format() method of each NumberFormat instance to format the BigDecimal amount as a currency string for each currency. Finally, we print the formatted currency strings to the console.
🌐
Heapcode
heapcode.com › format-currency-in-java
Format Currency in Java - HeapCode.COM
April 15, 2014 - Note: Observe the difference in currency formatting between France and German even though they both have Euro as currency. I Manjunath is a self confessed addict of Java and a strong supporter of OpenSource Technologies. I live in Bangalore, India. ... NumberFormat.getCurrencyInstance(new Locale(“en”, “IN”)); is not working for me. COuld you plss help ... Dont use Locale for India it will print Correctly in Indian Currency!!!
🌐
OneCompiler
onecompiler.com › java › 3xbhp3h75
Java Currency Formatter - Java - OneCompiler
OneCompiler's Java online editor supports stdin and users can give inputs to the programs using the STDIN textbox under the I/O tab. Using Scanner class in Java program, you can read the inputs.
Find elsewhere
🌐
FreeFormatter
freeformatter.com › india-standards-code-snippets.html
Formatting standards & code snippets for India - Freeformatter.com
import com.ibm.icu.util.ULocale; import com.ibm.icu.text.NumberFormat; ULocale locale = new ULocale("en", "IN"); // or "hi" NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); numberFormat.format(999999999.99d); double d = 999999999.99d; d.ToString("c", CultureInfo.GetCultureInfo("en-IN"))); // or "hi-IN" let number = 999999999.99; number.toLocaleString('en-IN', {currency: 'INR', style: 'currency'});
Top answer
1 of 16
183

I'd recommend using the java.text package:

double money = 100.1;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(money);
System.out.println(moneyString);

This has the added benefit of being locale specific.

But, if you must, truncate the String you get back if it's a whole dollar:

if (moneyString.endsWith(".00")) {
    int centsIndex = moneyString.lastIndexOf(".00");
    if (centsIndex != -1) {
        moneyString = moneyString.substring(1, centsIndex);
    }
}
2 of 16
159
double amount =200.0;
Locale locale = new Locale("en", "US");      
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
System.out.println(currencyFormatter.format(amount));

or

double amount =200.0;
System.out.println(NumberFormat.getCurrencyInstance(new Locale("en", "US"))
        .format(amount));

The best way to display currency

Output

$200.00

Note: Locale constructors have been deprecated. See Obtaining a Locale for other options.

So, since Locale constructors are deprecated, we can use Locale.Builder() to construct a Locale object.

    double amount =200.0;
    Locale locale = new Locale.Builder().setLanguage("en").setRegion("US").build();
    NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
    System.out.println(currencyFormatter.format(amount));

or

    double amount =200.0;
    System.out.println(NumberFormat.getCurrencyInstance(new Locale.Builder().setLanguage("en").setRegion("US").build()).format(amount));

Output

$200.00

If you don't want to use sign use this method

double amount = 200;
DecimalFormat twoPlaces = new DecimalFormat("0.00");
System.out.println(twoPlaces.format(amount));

200.00

This also can be use (With the thousand separator )

double amount = 2000000;    
System.out.println(String.format("%,.2f", amount));          

2,000,000.00

🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberFormat.html
Using Predefined Formats (The Java™ Tutorials > Internationalization > Formatting)
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. By invoking the methods provided by the NumberFormat class, you can format numbers, currencies, and percentages according to Locale.
🌐
How to do in Java
howtodoinjava.com › home › java date time › localized currency formatting in java
Localized Currency Formatting in Java
January 14, 2024 - Please note that NumberFormat class OR Currency class does not convert the currencies using exchange rate logic. They are plain representation according to the location data provided by Locale class. If you want to convert between currencies then add some more logic in your application. Below are the major Java classes which are used to format locale-based currencies.
🌐
Medium
kesia-feitosa.medium.com › find-a-solution-for-java-currency-formatter-f9f86f3d5854
Find a solution for Java Currency Formatter | by Kesia Feitosa | Medium
August 29, 2020 - The detailed description of the problem Java Currency Formatter is in the link below: ... My solution was very simple using NumberFormat class for the formats US, Chinese, and French that already existed and for the Indian format I used Locale class to create a new format.
🌐
Tabnine
tabnine.com › home page › code › java › java.text.numberformat
java.text.NumberFormat.getCurrencyInstance java code examples | Tabnine
double amount =200.0; Locale locale = new Locale("en", "US"); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale); System.out.println(currencyFormatter.format(amount)); ... import java.text.*; import java.math.*; import java.util.*; public class Test { public static void main(String[] args) { NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.US); BigDecimal value = new BigDecimal("12385748375889879879894375893475984.03"); System.out.println(currencyFormatter.format(value)); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › numberformat-getcurrencyinstance-method-in-java-with-examples
NumberFormat getCurrencyInstance() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Return Value: The function returns the NumberFormat instance for currency formatting. Below is the implementation of the above function: ... // Java program to implement // the above function import java.text.NumberFormat; import java.util.Locale; import java.util.Currency; public class Main { public static void main(String[] args) throws Exception { // Get the instance NumberFormat nF = NumberFormat .getCurrencyInstance( Locale.CANADA); // Stores the values String values = nF.getCurrency() .getDisplayName(); double amount = 4538.89; // Prints the currency System.out.println(values); // Print amount in defined currency System.out.println(nF.format(amount)); } }