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);
    }
}
Answer from duffymo on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberFormat.html
Using Predefined Formats (The Java™ Tutorials > Internationalization > Formatting)
By invoking the methods provided ... numbers, currencies, and percentages according to Locale. The material that follows demonstrates formatting techniques with a sample program called NumberFormatDemo.java. You can use the NumberFormat methods to format primitive-type numbers, such as double, and their corresponding wrapper objects, such as Double. The following code example formats a ...
Discussions

java - How to format decimals in a currency format? - Stack Overflow
Is there a way to format a decimal as following: 100 -> "100" 100.1 -> "100.10" If it is a round number, omit the decimal part. Otherwise format with two decimal places. More on stackoverflow.com
🌐 stackoverflow.com
question: How to format digits into dollar amounts
"never" use doubles for money. you lose precision. it is impossible to represent "0.1" as a float type number with a finite number of bits. http://javarevisited.blogspot.com/2012/02/java-mistake-1-using-float-and-double.html that being said, you can use DecimalFormat or the printf family of functions introduced in Java 5. They should work with float-types and BigDecimal; but it's been a while since I looked at it so the details are left as an exercise.... yada yada. More on reddit.com
🌐 r/java
6
3
September 11, 2012
format - Formatting Currencies in Foreign Locales in Java - Stack Overflow
Also, I've found java.text.NumberFormat, which will format a currency for a specific locale. My problem - util.Currency will provide proper symbols and codes for representing currencies in their non-default locales, but will not format currency in any locale-specific way. NumberFormat assumes that the number I pass it, with a locale, is the currency of that locale, not a foreign currency. For example... More on stackoverflow.com
🌐 stackoverflow.com
How can I add a currency format to an output

This will add a sign to the beginning of your currency string

String currencyWithSign = "$" + currency;
More on reddit.com
🌐 r/javahelp
4
1
August 31, 2019
🌐
Stevenschwenke
stevenschwenke.de › formattingCurrencyInJavaWithStringFormat
Formatting Currency in Java with string.format
August 24, 2020 - I only noticed that when I searched a library that would offer formatting methods. After searching for a while and wondering why so many libraries exist, a colleague found a surprisingly easy solution: String.format(). Here is some code to show how to format currency with plain Java.
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberintro.html
Numbers and Currencies (The Java™ Tutorials > Internationalization > Formatting)
For example, in France the number 123456.78 should be formatted as 123 456,78, and in Germany it should appear as 123.456,78. In this section, you will learn how to make your programs independent of the locale conventions for decimal points, thousands-separators, and other formatting properties.
🌐
HackerRank
hackerrank.com › challenges › java-currency-formatter › forum
Java Currency Formatter Discussions | Java | HackerRank
import java.io.*; import java.util.*; import java.text.NumberFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); NumberFormat usFormat = NumberFormat.getCurrencyInstance(Locale.US); String us = usFormat.format(payment); Locale indiaLocale = new Locale("en", "IN"); NumberFormat indiaFormat = Number
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 › 8 › docs › api › java › text › NumberFormat.html
NumberFormat (Java Platform SE 8 )
4 days ago - The returned number format is configured to round floating point numbers to the nearest integer using half-even rounding (see RoundingMode.HALF_EVEN) for formatting, and to parse only the integer part of an input string (see isParseIntegerOnly). ... Returns a currency format for the current default FORMAT locale.
Find elsewhere
🌐
Educative
educative.io › answers › how-to-format-a-number-as-currency-depending-on-locale-in-java
How to format a number as currency depending on Locale in Java
Line 9: We get the currency format for France using the getCurrencyInstance() method. The FRANCE locale is passed as an argument to the method. We name the obtained format as franceFormat.
🌐
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.
🌐
Avajava
avajava.com › tutorials › lessons › how-do-i-use-numberformat-to-format-currencies.html
How do I use NumberFormat to format currencies?
This is our free web tutorial index that features a variety of topics related to Java web application development.
🌐
Blogger
javarevisited.blogspot.com › 2014 › 02 › how-to-format-and-display-number-to.html
How to Format and Display Number to Currency in Java - Example Tutorial
April 9, 2025 - All you need to do is to get correct Currency Instance-based upon Locale, for example, to display the amount in US dollar, call NumberFormat.getCurrencyInstance() method with Locale as Locale.US, similarly to display currency as UK pound sterling, ...
🌐
How to do in Java
howtodoinjava.com › home › java date time › localized currency formatting in java
Localized Currency Formatting in Java
January 14, 2024 - I am first listing the classes used in examples, and then we will look at the real example codes. 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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › numberformat-setcurrency-method-in-java-with-examples
NumberFormat setCurrency() method in Java with Examples - GeeksforGeeks
July 11, 2025 - UnsupportedOperationException: it is thrown if the number format class doesn't implement currency formatting · NullPointerException it is thrown if currency is null Below is the implementation of the above function: Program 1: ... // 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 { NumberFormat nF = NumberFormat.getNumberInstance(); // Initially currency System.out.println("Initially Currency: " + nF.getCurrency()); // Currency set to US nF.setCurrency(Currency .getInstance(Locale.CANADA)); // Print the currency System.out.println("Currency set as: " + nF.getCurrency()); } }
🌐
Kodejava
kodejava.org › how-do-i-format-a-number-as-currency-string
How do I format a number as currency string? - Learn Java by Examples
July 4, 2024 - For this purpose you can use the ... public class LocaleCurrencyFormat { public static void main(String[] args) { Double number = 1500D; // Format currency for Canada locale in Canada locale, // the decimal point symbol is ...
🌐
ZetCode
zetcode.com › java › numberformat
Java NumberFormat - formatting numbers and currencies in Java
July 4, 2024 - This line gets the number format for the Chinese currency. $ java Main.java $23,500.00 23 500,00 € ¥23,500.00
🌐
Reddit
reddit.com › r/java › question: how to format digits into dollar amounts
r/java on Reddit: question: How to format digits into dollar amounts
September 11, 2012 -

Im doing some homework thats due in a few weeks and i was just wondering, i have to display some doubles to the hundredth place for dollar amounts, some doubles, which should be $5.00 are only showing up as $5.0, and some doubles, lets just say 5.23423523523 i want to be $2.23, any tips?

🌐
GeeksforGeeks
geeksforgeeks.org › java › numberformat-getcurrencyinstance-method-in-java-with-examples
NumberFormat getCurrencyInstance() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Below is the implementation of ... Currency.getInstance( Locale.CANADA)); // Stores the values String values = nF.getCurrency() .getDisplayName(); int amount = 1078; // Prints the currency name System.out.println(values); // Print ...
🌐
Fgcu
ruby.fgcu.edu › courses › mpenderg › ism3230Notes › decimalformatobject.html
Decimal Format Object
Once the format object has been created, then it can be used when converting numbers to strings using its format method. For example: double salary = 29123.4403; DecimalFormat currency= new DecimalFormat("$ #,##0.00");
Top answer
1 of 8
62

Try using setCurrency on the instance returned by getCurrencyInstance(Locale.GERMANY)

Broken:

java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
System.out.println(format.format(23));

Output: 23,00 €

Fixed:

java.util.Currency usd = java.util.Currency.getInstance("USD");
java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
format.setCurrency(usd);
System.out.println(format.format(23));

Output: 23,00 USD

2 of 8
29

I would add to answer from les2 https://stackoverflow.com/a/7828512/1536382 that I believe the number of fraction digits is not taken from the currency, it must be set manually, otherwise if client (NumberFormat) has JAPAN locale and Currency is EURO or en_US, then the amount is displayed 'a la' Yen', without fraction digits, but this is not as expected since in euro decimals are relevant, also for Japanese ;-).

So les2 example could be improved adding format.setMaximumFractionDigits(usd.getDefaultFractionDigits());, that in that particular case of the example is not relevant but it becomes relevant using a number with decimals and Locale.JAPAN as locale for NumberFormat.

    java.util.Currency usd = java.util.Currency.getInstance("USD");
    java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(
          java.util.Locale.JAPAN);
    format.setCurrency(usd);
    System.out.println(format.format(23.23));
    format.setMaximumFractionDigits(usd.getDefaultFractionDigits());
    System.out.println(format.format(23.23));

will output:

USD23
USD23.23

In NumberFormat code something similar is done for the initial/default currency of the format, calling method DecimalFormat#adjustForCurrencyDefaultFractionDigits. This operation is not done when the currency is changed afterwards with NumberFormat.setCurrency

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.text.numberformat.getcurrencyinstance
NumberFormat.GetCurrencyInstance(Locale) Method (Java.Text) | Microsoft Learn
Returns a currency format for the specified locale. [Android.Runtime.Register("getCurrencyInstance", "(Ljava/util/Locale;)Ljava/text/NumberFormat;", "")] public static Java.Text.NumberFormat GetCurrencyInstance(Java.Util.Locale inLocale);