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
🌐
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.
🌐
Reddit
reddit.com › r/java › double or float?
r/java on Reddit: Double or float?
July 23, 2017 -

Hello, I'm currently making a small matrix library in java, specifically for use with neural networks. So far I've done nearly all the functions and I used floats.

My question is if it would be better to use floats or doubles for this task, neural networks need precise values but are also very resource heavy.

Floats, doubles or write everything twice for overloading. Any ideas?

EDIT: Thanks for the answers, i finished version 1.0 today. If anyone wants to check it out feel free, just go here, hopefully it works well.

🌐
Reddit
reddit.com › r/learnjava › [new cs student]trouble differentiating between floats and doubles--why is 23.5 considered a double?
r/learnjava on Reddit: [New CS Student]Trouble differentiating between floats and doubles--why is 23.5 considered a double?
July 7, 2021 -

From my textbook:

When you write a floating-point literal in your program code, Java assumes it to be of the double data type. A double value is not compatible with a float variable because a double can be much larger or smaller than the allowable range for a float. As a result, code such as the following will cause an error:

Example 1:

float number;
number = 23.5;       //Error!

You can force a double to be treated as a float, by suffixing it with the letter F or f. The preceding code can be rewritten in the following manner to prevent an error:

Example 2:

float number;
number = 23.5F;       //This will work.

===================================================

I can't figure out why example 1 produces an error. Why is 23.5 considered a double? I thought it was a float.

AFAIK, float numbers are precise up to 7 decimal digits of accuracy. 23.5 only has 1 decimal digit. What am I not understanding? I thought by typing 'float number;' you are declaring the number variable to be a float. Why would you need the extra step of adding an F?

Thanks

🌐
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 ...
🌐
Reddit
reddit.com › r/learnjava › why use int/float?
r/learnjava on Reddit: Why use int/float?
January 19, 2015 -

Why would someone even use an int or a float?

I ask this because while int does use less data, you risk overflows and also in general a double is more accurate. How significant is the amount of data saved actually that one would choose that over a double?

Top answer
1 of 5
5

How significant is the amount of data saved actually that one would choose that over a double?

While i think that one of the most important points for using an int is really that it is an integer, i.e. pure with no decimals (as others have pointed out), i also wanted to address this question.

A double is twice as big as an int or float. This will not be an issue in a small program you write for a class and it won't even be an issue in many industry-level applications, but there are certainly times where doubling the amount of data that you have to transmit for no gain whatsoever (if you don't happen to need the added precision of a double) can have a huge impact. At work we often deal with the transmission of tens or hundreds of gigabytes of data. Of course, this number wouldn't be exactly twice as large if we used doubles instead of wherever possible, but it would certainly grow a substantial amount, which would certainly influence transmission times noticeably.

It is certainly fine to generally worry more about things like code readability than performance or space requirements, but there are applications where you do need to worry about size. And i don't think getting into the habit of using double "just because" is a good thing.

2 of 5
2

Most of what is said is only half correct. Remember that int/float and other primitive are represented using x amount of bits. In the days that java started off with embedded systems with limited memory thus you had to constraint how much memory your program could use to do operations and how much memory it needed to use overall. This is where good use of primitive types comes in.

Find elsewhere
🌐
Blogger
javarevisited.blogspot.com › 2016 › 05 › difference-between-float-and-double-in-java.html
Difference between float and double variable in Java? Example
It takes 8 bytes to store a variable while float just takes 4 bytes. This means if memory is a constraint then it's better to use float than double. By the way, the double type also has a larger range than float and if your numbers don't fit ...
🌐
Reddit
reddit.com › r/explainlikeimfive › eli5: difference between double and floating point data types
r/explainlikeimfive on Reddit: ELI5: difference between double and floating point data types
May 1, 2013 - They can have a lot of digits after the decimal point in the number. The actual difference between them is in size. According to the Java Language Specification, a float is a 32-bit value, while a double is a 64-bit value.
🌐
Reddit
reddit.com › r/learnpython › til a python float is the same (precision) as a java double
r/learnpython on Reddit: TIL a Python float is the same (precision) as a Java double
May 1, 2025 -

TL;DR in Java a "double" is a 64-bit float and a "float" is a 32-bit float; in Python a "float" is a 64-bit float (and thus equivalent to a Java double). There doesn't appear to be a natively implemented 32-bit float in Python (I know numpy/pandas has one, but I'm talking about straight vanilla Python with no imports).

In many programming languages, a double variable type is a higher precision float and unless there was a performance reason, you'd just use double (vs. a float). I'm almost certain early in my programming "career", I banged my head against the wall because of precision issues while using floats thus I avoided floats like the plague.

In other languages, you need to type a variable while declaring it.

Java: int age=30
Python: age=30

As Python doesn't have (or require?) typing a variable before declaring it, I never really thought about what the exact data type was when I divided stuff in Python, but on my current project, I've gotten in the habit of hinting at variable type for function/method arguments.

def do_something(age: int, name: str):

I could not find a double data type in Python and after a bunch of research it turns out that the float I've been avoiding using in Python is exactly a double in Java (in terms of precision) with just a different name.

Hopefully this info is helpful for others coming to Python with previous programming experience.

P.S. this is a whole other rabbit hole, but I'd be curious as to the original thought process behind Python not having both a 32-bit float (float) and 64-bit float (double). My gut tells me that Python was just designed to be "easier" to learn and thus they wanted to reduce the number of basic variable types.

🌐
Quora
quora.com › What-is-the-difference-between-using-double-for-floating-point-numbers-in-Java-as-opposed-to-using-float-or-long-in-C-C
What is the difference between using double for floating point numbers in Java as opposed to using float or long in C/C++? - Quora
Answer (1 of 2): Disclaimer: I am not a Java expert Question is sort of confusing. A long is an integral type, so I think we can ignore that part of the question. Computer languages provide some level of abstraction over the CPU. But that doesn’t mean they abandon the capabilities of the CPU an...
🌐
Reddit
reddit.com › r/gamedev › eli5: why games use floats instead of doubles when doubles are more precise?
r/gamedev on Reddit: ELI5: Why games use floats instead of doubles when doubles are more precise?
August 17, 2016 -

Newbie game dev here and I was looking around at some tutorials and noticed that most of them use floats for decimal values instead of doubles. From what I know, doubles have more precision that floats, so why don't they just all use doubles instead of floats?

🌐
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 - As the Float consumes less memory in comparison to the Double data type. By default, Java treats any decimal or float numbers as double type, so in case, if we want to define any value as float, we need to manually typecast it using the 'f' ...
🌐
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.
Top answer
1 of 5
12

Since your question is mostly about performance, this article presents you with some specific calculations (keep in mind though that this article is specific to neural networks, and your calculations may be completely different to what they're doing in the article): http://web.archive.org/web/20150310213841/http://www.heatonresearch.com/content/choosing-between-java%E2%80%99s-float-and-double

Some of the relevant material from the link is reproduced here:

Both double and float can support relatively large numbers. The upper and lower range are really not a consideration for neural networks. Float can handle numbers between 1.40129846432481707e-45 to 3.40282346638528860e+38...Basically, float can handle about 7 decimal places. A double can handle about 16 decimal places.

Matrix multiplication is one of the most common mathematical operations for neural network programming. By no means is it the only operation, but it will provide a good benchmark. The following program will be used to benchmark a double.

Skipping all the code, the table on the website shows that for a 100x100 matrix multiplication, they have a gain in performance of around 10% if they use doubles. For a 500x100 matrix multiplication, the performance loss because of using doubles is around 7%. And for a 1000x1000 matrix multiplication, that loss is around 17%.

For the small 100x100 matrix switching to float may actually decrease performance. As the size of the matrix increases, the percent gain increases. With a very large matrix the performance gain increases to 17%. 17% is worth considering.

2 of 5
10

Normally, I would use a double, because float doesn't have sufficient accuracy for many numerical use cases, and the performance difference is small enough not to matter.

As always, performance is implementation dependent so you will need to benchmark on your particular case in order to determine if it "matters" or not.

In general I have found:

  • The performance difference for individual operations is pretty small, especially on 64-bit machines. Both a float and a long will fit in a 64-bit machine word. Often there is zero difference.
  • floats have a slight advantage in that they consume less memory, and this can help with reducing CPU cache pressure. I've found floats to be 30-50% faster when doing simple operations over large arrays.
🌐
Quora
quora.com › Why-is-double-more-preferred-than-float-in-Java
Why is double more preferred than float in Java? - Quora
Answer (1 of 4): A double is a 64-bit, double-precision floating point number whereas float is a is a 32-bit, single-precision floating point number. To understand it better: Min float value = ~1.4E-45 Max float value = ~3.4028235E38 A float ...