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
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)
ISO 4217 is a standard published by the International Standards Organization. It specifies three-letter codes (and equivalent three-digit numeric codes) to represent currencies and funds. This standard is maintained by an external agency and is released independent of the Java SE platform.
Discussions

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
I'm doing my best to find a way to format foreign currencies across various locales which are not default for that currency, using Java. I've found java.util.Currency, which can represent the proper More on stackoverflow.com
🌐 stackoverflow.com
[JAVA] Trouble with Formatting Currency with 2 Decimal Points - Not a Statement Error
Fix your syntax. If you're unable to debug syntactical issues, I'd recommend avoiding complicated statements -- e.g. instead of writing: printf("bla bla bla" + (x / 20) + "more bla", a - 10, b, c); Instead write: String str = "bla bla bla" + (x / 20) + "more bla"; int i = a - 10; printf(str, i, b, c); // Now every argument is just a single variable This is semantically equivalent (and the arguments just got moved into their own variables). More on reddit.com
🌐 r/learnprogramming
9
1
February 23, 2021
How can I convert currency format to a different currency?
You probably want to get a NumberFormat with the US locale, for example System.out.println(NumberFormat.getCurrencyInstance(Locale.US).format(5)); prints $5.00. Another thing you could do it to call the setCurrency method of NumberFormat: NumberFormat nf = NumberFormat.getCurrencyInstance(); nf.setCurrency(Currency.getInstance(Locale.US)); System.out.println(nf.format(5)); Which prints US$5.00 for me. More on reddit.com
🌐 r/learnjava
2
2
December 7, 2021
🌐
Stevenschwenke
stevenschwenke.de › formattingCurrencyInJavaWithStringFormat
Formatting Currency in Java with string.format
August 24, 2020 - void formatCurrency(BigDecimal value) { // %, => local-specific thousands separator // .2f => positions after decimal point return String.format("%,.2f", price); } @Test void formattingOfBigDecimalToString() { BigDecimal priceToFormat = BigDecimal.valueOf(23356); String formattedPrice = formatCurrency(priceToFormat); assertEquals("23.356,00", formattedPrice); priceToFormat = BigDecimal.valueOf(3245.9); formattedPrice = formatCurrency(priceToFormat); assertEquals("3.245,90", formattedPrice); priceToFormat = BigDecimal.valueOf(89645.99); formattedPrice = formatCurrency(priceToFormat); assertEqua
🌐
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
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberintro.html
Numbers and Currencies (The Java™ Tutorials > Internationalization > Formatting)
Using the factory methods provided by the NumberFormat class, you can get locale-specific formats for numbers, currencies, and percentages.
🌐
Coderanch
coderanch.com › t › 665504 › java › create-custom-currency-format
How to create a custom currency format [Solved] (Java in General forum at Coderanch)
May 10, 2016 - I'm currently using the Taiwan Locale as a placeholder, but I'd like to know how to make a custom format. Current code is below: Thank you for your time! ... I'm not sure whether it answers your specific question, but you might have a look at the API documentation for the Currency class, starting from where it says · Oracle wrote:Users can supersede the Java runtime currency data by means of the system property java.util.currency.data.
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
getCurrencyInstance() is a static method of the NumberFormat class that returns the currency format for the specified locale. Note: A Locale in Java represents a specific geographical, political, or cultural region.
🌐
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?

🌐
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
May 28, 2023 - For this purpose you can use the NumberFormat.getCurrencyInstance() method and pass the correct Locale to get the currency format that you want. package org.kodejava.text; import java.text.NumberFormat; import java.util.Locale; public class ...
🌐
GitHub
gist.github.com › ccampo133 › e6315a4d2678be394ff62c7897bfaa48
Currency formatting · GitHub
Currency formatting. GitHub Gist: instantly share code, notes, and snippets.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › NumberFormat.html
NumberFormat (Java Platform SE 8 )
October 20, 2025 - 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.
🌐
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
🌐
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 - I believe that practice makes us better and on the HackerRank website there are many good practices in Java. So, for your practice before seeing the solution, try to solve it yourself. The problem that must be solved is about currency format. A double-precision number is informed and It is required to print with currency formats for the US, Indian, Chinese, and French.
🌐
Baeldung
baeldung.com › home › java › java numbers › number formatting in java
Number Formatting in Java | Baeldung
August 9, 2024 - DecimalFormat is one of the most popular ways to format a decimal number in Java.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › Currency.html
Currency (Java SE 17 & JDK 17)
January 20, 2026 - If a UTC datestamp is present and valid, the JRE will only use the new currency properties if the current UTC date is later than the date specified at class loading time. The format of the timestamp must be of ISO 8601 format : 'yyyy-MM-dd'T'HH:mm:ss'. For example,
🌐
OneCompiler
onecompiler.com › java › 3xbhp3h75
Java Currency Formatter - Java - OneCompiler
The editor shows sample boilerplate code when you choose language as Java and start coding.
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

🌐
Aspose.Cells
docs.aspose.com › cells › java › format-number-to-currency
How to Format Number as Currency|Documentation
In the Number group, click the dropdown arrow next to the number format box (this might display “General” by default). Choose Currency from the list.
🌐
Medium
medium.com › @AlexanderObregon › formatting-numbers-for-display-with-decimalformat-in-java-0577c0fe0b52
Formatting Numbers for Display with DecimalFormat in Java
June 27, 2025 - Learn how DecimalFormat works to display numbers with commas, decimals, or currency symbols and how to use it safely with formatting logic in Java.