There is a slight difference between these two formats. The "#.##" means it will print the number with maximum two decimal places whereas "#.00" means it will always display two decimal places and if the decimal places are less than two, it will replace them with zeros. see the example below with output.

public static final DecimalFormat df1 = new DecimalFormat( "#.##" );
public static final DecimalFormat df2 = new DecimalFormat( "#.00" );

System.out.println(df1.format(7.80));
System.out.println(df1.format(85));
System.out.println(df1.format(85.786));

System.out.println(df2.format(7.80));
System.out.println(df2.format(85));
System.out.println(df2.format(85.786));

And the output will be

7.8
85
85.79

7.80
85.00
85.79
Answer from Raza on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › DecimalFormat.html
DecimalFormat (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits.
🌐
Baeldung
baeldung.com › home › java › java numbers › a practical guide to decimalformat
A Practical Guide to DecimalFormat | Baeldung
January 8, 2024 - In this article, we’re going to explore the DecimalFormat class along with its practical usages. This is a subclass of NumberFormat, which allows formatting decimal numbers’ String representation using predefined patterns.
Discussions

Decimal Format

This is not the answer your professor is looking for... but please don't ever use double or float for monetary units. Things can go so wrong its not even funny... and the amount of time you spend looking for off by a penny errors will make you question your sanity.

The right way to do this would be to use BigDecimal on the value "12500" and then adjust the number to go from cents to dollars.

import java.math.BigDecimal;

public class BigD {
  public static void main (String[] args) {
    BigDecimal cents = new BigDecimal("12500");
    System.out.println(cents.toString());
    BigDecimal dollars = cents.movePointLeft(2);
    System.out.println(dollars.toString());
  }
}

(ideone)

Give Why not use Double or Float to represent currency? and When do rounding problems become a real problem? Is the least significant digit being one off really a big deal? a read. How to calculate monetary values in Java has another nice simple that shows some errors in floating point.

Even though you may be able to print the value out correctly, it doesn't mean that it is represented correctly.

12500 and 125 happen to be nice numbers in there... but 125.01 is actually 125.010000000000005115907697473

More on reddit.com
🌐 r/javahelp
8
7
April 10, 2017
[Java] DecimalFormat vs NumberFormat?
According to the documentation ( https://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html ), NumberFormat is an abstract base class for number formatting; DecimalFormat is a concrete derived class. But I think these are more about locale-specific formatting (commas or spaces between thousands etc). Are you just saying you want to display a double with 5 decimal places? More on reddit.com
🌐 r/learnprogramming
6
2
February 28, 2018
Double decimal formatting in Java - Stack Overflow
I'm having some problems formatting the decimals of a double. If I have a double value, e.g. 4.0, how do I format the decimals so that it's 4.00 instead? More on stackoverflow.com
🌐 stackoverflow.com
[JAVA] Cannot convert from double to decimal format.

DecimalFormat is not a numerical type. It does not do calculations or hold numbers. It is a type designed to help PRINT OUT a numerical type.

    double taxTotal;
    DecimalFormat formatter = new DecimalFormat ("$###,###.##");
    // blah blah

   string formattedValue = formatter.format(taxTotal)
   System.out.print("Your 2012 tax is " + formattedValue );

Note: You shouldn't use floating point types (i.e. float or duuble) to store money

  1. http://www.javapractices.com/topic/TopicAction.do?Id=13

  2. http://stackoverflow.com/questions/285680/representing-monetary-values-in-java

More on reddit.com
🌐 r/learnprogramming
13
2
January 10, 2013
🌐
GeeksforGeeks
geeksforgeeks.org › java › decimalformat-topattern-method-in-java
DecimalFormat toPattern() method in Java - GeeksforGeeks
April 1, 2019 - // Java program to illustrate the // toPattern() method import java.text.DecimalFormat; public class GFG { public static void main(String[] args) { // Create a DecimalFormat instance DecimalFormat deciFormat = new DecimalFormat(); // Apply a new pattern deciFormat.applyPattern("##, ##.##"); // Convert the current formatting state // to a string object String pattern = deciFormat.toPattern(); System.out.println(pattern); } }
🌐
University of Arizona
www2.cs.arizona.edu › classes › cs210 › fall17 › lectures › decimal_format.pdf pdf
Java API: java.text.DecimalFormat
• The format string: #,###.## indicates the answer is to have no more than two · decimal places. • The value will be correctly rounded automatically when printed. • Example: import java.text.DecimalFormat; public class FormatExample2 { public static void main(String[] args) { float oneNum = 3.14159F; double nextNum = 3827967.29836598263987649826395809384756; DecimalFormat commaFormat; commaFormat = new DecimalFormat("#,###.##"); String myPi = commaFormat.format(oneNum); System.out.println("oneNum ·
🌐
Fgcu
ruby.fgcu.edu › courses › mpenderg › ism3230Notes › decimalformatobject.html
Decimal Format Object
import java.text.*; To use a format object you must first declare and create it. This can be done in one line. For a currency this would look like. DecimalFormat currency = new DecimalFormat("$ #,##0.00");
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java-internationalization › decimalformat.html
Java DecimalFormat
June 23, 2014 - The java.text.DecimalFormat class is used to format numbers using a formatting pattern you specify yourself.
🌐
Coderanch
coderanch.com › t › 386829 › java › DecimalFormat
DecimalFormat (Beginning Java forum at Coderanch)
It's quite simple if your read the API for it. double d = 123456.7890 DecimalFormat df = new DecimalFormat("#,##0.00"); System.out.println(df.format(d)); This will give you 123,456.79 If you really wish to code this to handle the local you are at there are methods to do that as well so, if ran in another local the output might look like: 123.456,79
🌐
TutorialsPoint
tutorialspoint.com › java_i18n › java_i18n_decimalformat.htm
Java Internationalization - DecimalFormat Class
In this example, we're formatting numbers based on a given pattern. import java.text.DecimalFormat; public class I18NTester { public static void main(String[] args) { String pattern = "####,####.##"; double number = 123456789.123; DecimalFormat numberFormat = new DecimalFormat(pattern); System.out.println(number); System.out.println(numberFormat.format(number)); } }
🌐
Reddit
reddit.com › r/javahelp › decimal format
r/javahelp on Reddit: Decimal Format
April 10, 2017 -

Im trying to turn a string number of "12500" into the formatted version of "$125.00", but whenever i use the Decimal format it wont put the Decimal between the "125" and "00" after using the format ("$###.##"). Im assuming its a simple fix, but im just stuck.. Any help?

Top answer
1 of 4
4

This is not the answer your professor is looking for... but please don't ever use double or float for monetary units. Things can go so wrong its not even funny... and the amount of time you spend looking for off by a penny errors will make you question your sanity.

The right way to do this would be to use BigDecimal on the value "12500" and then adjust the number to go from cents to dollars.

import java.math.BigDecimal;

public class BigD {
  public static void main (String[] args) {
    BigDecimal cents = new BigDecimal("12500");
    System.out.println(cents.toString());
    BigDecimal dollars = cents.movePointLeft(2);
    System.out.println(dollars.toString());
  }
}

(ideone)

Give Why not use Double or Float to represent currency? and When do rounding problems become a real problem? Is the least significant digit being one off really a big deal? a read. How to calculate monetary values in Java has another nice simple that shows some errors in floating point.

Even though you may be able to print the value out correctly, it doesn't mean that it is represented correctly.

12500 and 125 happen to be nice numbers in there... but 125.01 is actually 125.010000000000005115907697473

2 of 4
2

Are you saying you want a String value "12500" to be formatted as "$125.00"? I'm not sure what you've tried exactly, but I think you'd want to convert the string a numeric data type (e.g. double, int, etc.), divide by 100, and format that result. Or, depending on your situation, you might be able to avoid converting to a numeric type, and just do some simple string manipulation instead.

🌐
Reddit
reddit.com › r/learnprogramming › [java] decimalformat vs numberformat?
r/learnprogramming on Reddit: [Java] DecimalFormat vs NumberFormat?
February 28, 2018 -

I find the area of an object and store it in a type double. If I want a specific number of decimal places, say 5, which one is better to use?

e.g. 4.55 > 4.55000,

But I guess maybe I need to understand the idea of decimal places. If a number is 4.555555, rounded to 5 decimal places, will it be 4.55556? If so, will the DecimalFormat be what I need to look into? I see if I do #.##### it will round down, but if I use zeroes, it will round normally like in math: #.00000.

If this is correct..can someone tell me the difference between number format and decimal format then? When to use each.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.text.decimalformat
DecimalFormat Class (Java.Text) | Microsoft Learn
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. [Android.Runtime.Register("java/text/DecimalFormat", DoNotGenerateAcw=true)] public class DecimalFormat : Java.Text.NumberFormat
🌐
Android Developers
developer.android.com › api reference › decimalformat
DecimalFormat | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
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 › javase › tutorial › i18n › format › decimalFormat.html
Customizing Formats (The Java™ Tutorials > Internationalization > Formatting)
This class allows you to control the display of leading and trailing zeros, prefixes and suffixes, grouping (thousands) separators, and the decimal separator. If you want to change formatting symbols, such as the decimal separator, you can use the DecimalFormatSymbols in conjunction with the DecimalFormat class.
🌐
Quora
quora.com › How-do-I-set-decimal-places-in-Java
How to set decimal places in Java - Quora
Answer (1 of 2): In what context? What are you trying to do? If you’re calculating floating point numbers, and just need to display them with a certain number of digits of precision, you can perform the calculations at full scale, and then round to whatever level of precision you need.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Format-double-Java-printf-example
How to format a Java double with printf example
It is a common requirement to format currencies to two decimal places. You can easily achieve this with the Java printf function. Just use %.2f as the format specifier.
🌐
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.
🌐
Coderanch
coderanch.com › t › 373804 › java › DecimalFormat-format-decimal-digits
Using DecimalFormat to format decimal digits. (Java in General forum at Coderanch)
June 8, 2004 - Java in General · Mani Ram · Ranch Hand · Posts: 1140 · posted 21 years ago · Number of slices to send: Optional 'thank-you' note: Send · Look at the following piece of code Why the number of decimal digits gets restricted to 3 for printlns 5 & 6, even when I haven't specified the maximum fraction digits (using setMaximumFractionDigits())? Basically I want to format the number only when the number of fraction digits is less than 2.