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 OverflowOracle
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. The material that follows demonstrates formatting techniques with a sample program called NumberFormatDemo.java.
Videos
05:44
Using Java number and printing them as currency - YouTube
Formatting Money & Percents in Java using the ...
01:51
Java Currency Number Format | How to Currency Format in Java | ...
03:54
[SOLVED!] Java Currency Formatter - HackerRank - YouTube
Java Currency Formatter Hackerrank Solution | Hackerrank ...
19:43
Java Currency Formatter Practice Program #97 - YouTube
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 )
1 week 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.
HackerRank
hackerrank.com › challenges › java-currency-formatter › problem
Java Currency Formatter | 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. Then print the formatted values as follows:
How to do in Java
howtodoinjava.com › home › java date time › localized currency formatting in java
Localized Currency Formatting in Java
January 14, 2024 - Java Date Time · Currency Formatting, i18n · Most of the applications today, which are targeted at a larger audience e.g. internet users, usually deal in money as well. In such applications, a requirement will be to display money/currency in a format specific to that location or country.
Spring
docs.spring.io › spring-framework › docs › 3.2.0.M2_to_3.2.0.RC1 › Spring Framework 3.2.0.RC1 › org › springframework › format › number › CurrencyFormatter.html
CurrencyFormatter - Spring
A BigDecimal formatter for currency values. Delegates to NumberFormat.getCurrencyInstance(Locale). Configures BigDecimal parsing so there is no loss of precision. Can apply a specified RoundingMode to parsed values. Since: 3.0 · Author: Keith Donald, Juergen Hoeller · See Also: ...
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. Line 10: We get the formatted currency string using the format() method on franceFormat.
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
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.
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. Then print the formatted values as follows:
Author kanika011
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.
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.
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
* * @author */ public class Test { public static void main(String args[]) { double price = 100.25; showPriceInUSD(price, getExchangeRate("USD")); showPriceInGBP(price, getExchangeRate("GBP")); showPriceInJPY(price, getExchangeRate("JPY")); } /** * Display price in US Dollar currency * * @param price * @param rate */ public static void showPriceInUSD(double price, double rate) { double priceInUSD = price * rate; NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US); System.out.printf("Price in USD : %s %n", currencyFormat.format(priceInUSD)); } /** * Display prince in Britis
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberintro.html
Numbers and Currencies (The Java™ Tutorials > Internationalization > Formatting)
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. Using the factory methods provided by the NumberFormat class, you can get locale-specific formats for numbers, currencies, and percentages.
GeeksforGeeks
geeksforgeeks.org › java › numberformat-getcurrencyinstance-method-in-java-with-examples
NumberFormat getCurrencyInstance() method in Java with Examples - GeeksforGeeks
July 11, 2025 - // 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 currency instance NumberFormat nF = NumberFormat .getCurrencyInstance(); // Sets the currency to Canadian Dollar nF.setCurrency( Currency.getInstance( Locale.CANADA)); // Stores the values String values = nF.getCurrency() .getDisplayName(); int amount = 1078; // Prints the currency name System.out.println(values); // Print amount in defined currency System.out.println(nF.format(amount)); } }
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()); } }
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.