Doubles take up twice the amount of memory as floats do (hence the name) but as a result they are more precise and can represent a wider range of values. Memory space doesn’t matter as much as it used to so for most use cases, doubles are just fine. In certain applications though where speed and performance is a higher priority than accuracy, such as graphics calculations for video games, using floats instead of doubles may be preferable. Answer from Quantum-Bot on reddit.com
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits. A double is twice the size of a float — thus the term double. In Java, the Float and Double wrapper classes have two properties that ...
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - A float is a 32-bit single-precision floating-point type, occupying four bytes of memory. This compact size makes it well-suited for memory-constrained environments like embedded systems and mobile devices.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › difference-between-float-and-double
Difference between Float and Double - GeeksforGeeks
July 23, 2025 - The key difference is their precision and storage size. A float is typically a 32-bit number with a precision of about 7 decimal digits, while a double is a 64-bit number with a precision of about 15 decimal digits.
🌐
Reddit
reddit.com › r/learnprogramming › float vs. double – what's the key difference?"
r/learnprogramming on Reddit: float vs. double – What's the Key Difference?"
November 2, 2024 -

New to programming and curious: what's the main difference between float and double? When should I use one over the other?

Thanks! 🙏😊

Top answer
1 of 5
19
It can depend on the language spec, but usually the amount of memory and therefore the precision allowed by the type. Usually: A double will use 8 bytes or 64 bits of memory while a float uses only 4 bytes or 32 bits. This means that a float is less precise since it can store fewer digits after the decimal place. The way it works is that some bits of the datatype are used for the whole number portion of the number and some for the decimal portion. So as you can see, double, using more memory can have more bits allocated to the decimal portion making it more precise. See balefrost's reply to my comment for a correct explanation of this. Using float means using less memory, having more efficient code (due to lower precision so saving on calculations) and handling a smaller range of numbers (floats handle a smaller range than double due to reduced memory usage). Hope this helps!
2 of 5
3
The difference is memory size. Floats in Java (which I assume is the language you’re talking about) take up 32 bits of memory, the same as an integer. Doubles, as you might guess from the name, take up double the space: 64 bits. Doubles use those extra bits to both store a wider range of numbers and add more precision to the numbers they can store as well. There’s really seldom any reason to use floats in modern Java applications since memory is no longer a limiting factor for most programs. However, back in the day memory used to be much more limited so you would stick to regular floats as long as they were good enough for what you’re doing and only use doubles when absolutely necessary. This was starting to change even as Java was first created, but a lot of things in Java were designed to make the transition easier for programmers who were used to using C, a popular language at the time.
🌐
GeeksforGeeks
geeksforgeeks.org › java › comparison-of-double-and-float-primitive-types-in-java
Comparison of double and float primitive types in Java - GeeksforGeeks
March 6, 2023 - The output is true in the first example and false in second. We know that precisions of float and double are different. Size of mantissa for float is 24 and 53 for double. Let us consider the first example of 5.25. Binary representation of integral part is 101 and binary representation of part of the dot is 0.01 (needs only two bits) Let us consider the second example 5.1.
Find elsewhere
🌐
Medium
medium.com › @qingedaig › java-bigdecimal-vs-double-vs-float-012c7149e550
Java BigDecimal vs double vs float | by Alice Dai | Medium
October 15, 2024 - Memory: Use float when memory is a concern and lower precision is acceptable. Choosing the right data type depends on your specific needs regarding precision, performance, and the nature of the calculations you are performing. For most financial applications, BigDecimal is recommended, while double is commonly used for scientific computations.
Top answer
1 of 5
28

It's because the closest float value to 1.3 isn't the same as the closest double value to 1.3. Neither value will be exactly 1.3 - that can't be represented exactly in a non-recurring binary representation.

To give a different understanding of why this happens, suppose we had two decimal floating point types - decimal5 and decimal10, where the number represents the number of significant digits. Now suppose we tried to assign the value of "a third" to both of them. You'd end up with

decimal5 oneThird = 0.33333
decimal10 oneThird = 0.3333333333

Clearly those values aren't equal. It's exactly the same thing here, just with different bases involved.

However if you restrict the values to the less-precise type, you'll find they are equal in this particular case:

double d = 1.3d;
float f = 1.3f;
System.out.println((float) d == f); // Prints true

That's not guaranteed to be the case, however. Sometimes the approximation from the decimal literal to the double representation, and then the approximation of that value to the float representation, ends up being less accurate than the straight decimal to float approximation. One example of this 1.0000001788139343 (thanks to stephentyrone for finding this example).

Somewaht more safely, you can do the comparison between doubles, but use a float literal in the original assignment:

double d = 1.3f;
float f = 1.3f;
System.out.println(d == f); // Prints true

In the latter case, it's a bit like saying:

decimal10 oneThird = 0.3333300000

However, as pointed out in the comments, you almost certainly shouldn't be comparing floating point values with ==. It's almost never the right thing to do, because of precisely this sort of thing. Usually if you want to compare two values you do it with some sort of "fuzzy" equality comparison, checking whether the two numbers are "close enough" for your purposes. See the Java Traps: double page for more information.

If you really need to check for absolute equality, that usually indicates that you should be using a different numeric format in the first place - for instance, for financial data you should probably be using BigDecimal.

2 of 5
12

A float is a single precision floating point number. A double is a double precision floating point number. More details here: http://www.concentric.net/~Ttwang/tech/javafloat.htm

Note: It is a bad idea to check exact equality for floating point numbers. Most of the time, you want to do a comparison based on a delta or tolerance value.

For example:

float a = 1.3f;
double b = 1.3;
float delta = 0.000001f;
if (Math.abs(a - b) < delta)
{
    System.out.println("Close enough!");
}
else
{
    System.out.println("Not very close!");
}

Some numbers can't be represented exactly in floating point (e.g. 0.01) so you might get unexpected results when you compare for equality.

Top answer
1 of 7
15

If you're converting doubles to floats and the difference between them is beyond the precision of the float type, you can run into trouble.

For example, say you have the two double values:

9.876543210
9.876543211

and that the precision of a float was only six decimal digits. That would mean that both float values would be 9.87654, hence equal, even though the double values themselves are not equal.

However, if you're talking about floats being cast to doubles, then identical floats should give you identical doubles. If the floats are different, the extra precision will ensure the doubles are distinct as well.

2 of 7
9

As long as you are not mixing promoted floats and natively calculated doubles in your comparison you should be ok, but take care:

Comparing floats (or doubles) for equality is difficult - see this lengthy but excellent discussion.

Here are some highlights:

  1. You can't use ==, because of problems with the limited precision of floating point formats

  2. float(0.1) and double(0.1) are different values (0.100000001490116119384765625 and 0.1000000000000000055511151231257827021181583404541015625) respectively. In your case, this means that comparing two floats (by converting to double) will probably be ok, but be careful if you want to compare a float with a double.

  3. It's common to use an epsilon or small value to make a relative comparison with (floats a and b are considered equal if a - b < epsilon). In C, float.h defines FLT_EPSILON for exactly this purpose. However, this type of comparison doesn't work where a and b are both very small, or both very large.

  4. You can address this by using a scaled-relative-to-the-sizes-of-a-and-b epsilon, but this breaks down in some cases (like comparisons to zero).

  5. You can compare the integer representations of the floating point numbers to find out how many representable floats there are between them. This is what Java's Float.equals() does. This is called the ULP difference, for "Units in Last Place" difference. It's generally good, but also breaks down when comparing against zero.

The article concludes:

Know what you’re doing

There is no silver bullet. You have to choose wisely.

  • If you are comparing against zero, then relative epsilons and ULPs based comparisons are usually meaningless. You’ll need to use an absolute epsilon, whose value might be some small multiple of FLT_EPSILON and the inputs to your calculation. Maybe.
  • If you are comparing against a non-zero number then relative epsilons or ULPs based comparisons are probably what you want. You’ll probably want some small multiple of FLT_EPSILON for your relative epsilon, or some small number of ULPs. An absolute epsilon could be used if you knew exactly what number you were comparing against.
  • If you are comparing two arbitrary numbers that could be zero or non-zero then you need the kitchen sink. Good luck and God speed.

So, to answer your question:

  • If you are downgrading doubles to floats, then you might lose precision, and incorrectly report two different doubles as equal (as paxdiablo points out.)
  • If you are upgrading identical floats to double, then the added precision won't be a problem unless you are comparing a float with a double (Say you'd got 1.234 in float, and you only had 4 decimal digits of accuracy, then the double 1.2345 MIGHT represent the same value as the float. In this case you'd probably be better to do the comparison at the precision of the float, or more generally, at the error level of the most inaccurate representation in the comparison).
  • If you know the number you'll be comparing with, you can follow the advice quoted above.
  • If you're comparing arbitrary numbers (which could be zero or non-zero), there's no way to compare them correctly in all cases - pick one comparison and know its limitations.

A couple of practical considerations (since this sounds like it's for an assignment):

  • The epsilon comparison mentioned by most is probably fine (but include a discussion of the limitations in the write up). If you're ever planning to compare doubles to floats, try to do it in float, but if not, try to do all comparisons in double. Even better, just use doubles everywhere.

  • If you want to totally ace the assignment, include a write-up of the issues when comparing floats and the rationale for why you chose any particular comparison method.

🌐
Codefinity
codefinity.com › blog › Float-vs-Double
Float vs Double
Both are used to represent floating ... storage requirements. The float type, typically a single-precision 32-bit IEEE 754 floating point, is used for decimal values that do not require extreme precision....
🌐
Scaler
scaler.com › home › topics › float vs double in java - difference you should know
Float Vs Double in Java - Difference You Should Know - Scaler Topics
March 27, 2024 - Double is a 64-bit floating-point number, which means that it can store up to 15 decimal digits accurately. The float keyword in Java is a primitive data type, and its size limit is 4 byte or 32 bits (1 byte = 8 bits) single-precision IEEE 754 ...
🌐
Quora
quora.com › What-is-the-difference-between-double-long-float-and-int-variables-in-Java-Which-one-should-be-used-for-storing-large-numbers-more-than-two-digits-Why
What is the difference between double, long, float, and int variables in Java? Which one should be used for storing large numbers (more than two digits)? Why? - Quora
Answer: In Java, int and long are primitive integer datatypes. They store integers as two‘s complement numbers. Ints use 32 bits and have a range from -2^{31}=-2147483648 to 2^{31}-1=2147483647, longs use 64 bits and have a range from -2^{63}=-9223372036854775808 to 2^{63}-1=9223372036854775807.
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
Sololearn
sololearn.com › en › Discuss › 2059751 › whats-the-difference-between-float-double-and-long-variables
What's the difference between float , double and long variables? | Sololearn: Learn to code for FREE!
November 5, 2019 - But double on the other hand has 8 bytes of storage and can as well store decimal point values with higher precision. 5th Nov 2019, 3:43 PM · Avinesh · Answer · Learn more efficiently, for free: Introduction to Python · 7.1M learners · ...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
Its range of values is beyond the ... Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers....
🌐
FavTutor
favtutor.com › blogs › java-float-vs-double
Java: Float vs Double | 4 Main Differences (& when to use?) | FavTutor
February 23, 2021 - This loss of bits from the end of the number is very pronounced while using float. The number of bits lost is much lesser while using double because of the large number of bits allocated for the exponent. Default: Double is the default data type used by Java for dealing with fractional numbers.
🌐
Simplilearn
simplilearn.com › home › resources › software development › float vs double in java: key differences you should know
Float vs Double in Java: Key Differences You Should Know
November 17, 2025 - Explore the key differences between float and double in Java. Our comprehensive guide helps you choose the right type for your Java applications. Perfect for new coders!