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
🌐
W3Schools
w3schools.com › java › ref_keyword_float.asp
Java float Keyword
Java Examples Java Videos Java ... Interview Q&A Java Certificate ... The float keyword is a data type that can store fractional numbers from 3.4e−038 to 3.4e+038....
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Float class wraps a value of primitive type float in an object.
Discussions

java - What is the difference between the float and integer data type when the size is the same? - Stack Overflow
What the difference between the float and integer data type when size is same? More on stackoverflow.com
🌐 stackoverflow.com
floating point - What is float in Java? - Stack Overflow
I wrote this code: float b = 3.6; and I get this: Error:Unresolved compilation problem: Type mismatch: cannot convert from double to float Why? Whats the definition of float? More on stackoverflow.com
🌐 stackoverflow.com
memory - Why are floats still part of the Java language when doubles are mostly recommended instead? - Software Engineering Stack Exchange
In every place I've looked, it says that double is superior to float in almost every way. float has been made obsolete by double in Java, so why is it still used? I program a lot with Libgdx, and ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
April 26, 2016
floating point - Float and double datatype in Java - Stack Overflow
The float data type is a single-precision 32-bit IEEE 754 floating point and the double data type is a double-precision 64-bit IEEE 754 floating point. What does it mean? And when should I use float More on stackoverflow.com
🌐 stackoverflow.com
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The float keyword in Java is a primitive data type that represents a single-precision 32-bit IEEE 754 floating point.
Top answer
1 of 3
118
  • float stores floating-point values, that is, values that have potential decimal places
  • int only stores integral values, that is, whole numbers

So while both are 32 bits wide, their use (and representation) is quite different. You cannot store 3.141 in an integer, but you can in a float.

Dissecting them both a little further:

In an integer, all bits except the leftmost one are used to store the number value. This is (in Java and many computers too) done in the so-called two's complement, which support negatives values. Two's complement uses the leftmost bit to store the positive (0) or negative sign (1). This basically means that you can represent the values of −231 to 231 − 1.

In a float, those 32 bits are divided between three distinct parts: The sign bit, the exponent and the mantissa. They are laid out as follows:

S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM

There is a single bit that determines whether the number is negative or non-negative (zero is neither positive nor negative, but has the sign bit set to zero). Then there are eight bits of an exponent and 23 bits of mantissa. To get a useful number from that, (roughly) the following calculation is performed:

M × 2E

(There is more to it, but this should suffice for the purpose of this discussion)

The mantissa is in essence not much more than a 24-bit integer number. This gets multiplied by 2 to the power of the exponent part, which, roughly, is a number between −128 and 127.

Therefore you can accurately represent all numbers that would fit in a 24-bit integer but the numeric range is also much greater as larger exponents allow for larger values. For example, the maximum value for a float is around 3.4 × 1038 whereas int only allows values up to 2.1 × 109.

But that also means, since 32 bits only have 4.2 × 109 different states (which are all used to represent the values int can store), that at the larger end of float's numeric range the numbers are spaced wider apart (since there cannot be more unique float numbers than there are unique int numbers). You cannot represent some numbers exactly, then. For example, the number 2 × 1012 has a representation in float of 1,999,999,991,808. That might be close to 2,000,000,000,000 but it's not exact. Likewise, adding 1 to that number does not change it because 1 is too small to make a difference in the larger scales float is using there.

Similarly, you can also represent very small numbers (between 0 and 1) in a float but regardless of whether the numbers are very large or very small, float only has a precision of around 6 or 7 decimal digits. If you have large numbers those digits are at the start of the number (e.g. 4.51534 × 1035, which is nothing more than 451534 follows by 30 zeroes – and float cannot tell anything useful about whether those 30 digits are actually zeroes or something else), for very small numbers (e.g. 3.14159 × 10−27) they are at the far end of the number, way beyond the starting digits of 0.0000...

2 of 3
3

Floats are used to store a wider range of number than can be fit in an integer. These include decimal numbers and scientific notation style numbers that can be bigger values than can fit in 32 bits. Here's the deep dive into them: http://en.wikipedia.org/wiki/Floating_point

🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › lang › Float.html
Float (Java SE 22 & JDK 22)
July 16, 2024 - In addition, this class provides several methods for converting a float to a String and a String to a float, as well as other constants and methods useful when dealing with a float. This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. The class java.lang.Double has a discussion of equality, equivalence, and comparison of floating-point values that is equally applicable to float values.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.float
Float Class (Java.Lang) | Microsoft Learn
The Float class wraps a value of primitive type float in an object. [Android.Runtime.Register("java/lang/Float", DoNotGenerateAcw=true)] public sealed class Float : Java.Lang.Number, IConvertible, IDisposable, Java.Interop.IJavaPeerable, ...
🌐
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?
The key difference between a float and double in Java is that a double can represent much larger numbers than a float. Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits.
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - Java provides two primitive data types for floating-point arithmetic: float and double. Both adhere to the IEEE 754 standard, ensuring consistent behavior across platforms.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-illustrate-the-usage-of-floating
Java Program to Illustrate the Usage of Floating - GeeksforGeeks
September 7, 2021 - Float: It is a single-precision value that has 32 bits in storage. and this single precision is faster and does take less size compared to double precision. For java variables, we can use float while declaring or initializing for expected value ...
🌐
Quora
quora.com › Why-if-we-declare-a-float-variable-in-Java-we-write-f-3-14f
Why if we declare a float variable in Java we write f (3.14f)? - Quora
Answer (1 of 3): Because without the “f” the number would be implicitly created as double. There are things called literals [1] which are helpful to specify the exact data type for a hardcoded number. Some examples in Java (you can find them all in the footnote): * 123456L or 123456l => long ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › float-floatvalue-in-java-with-examples
Float floatValue() in Java with examples - GeeksforGeeks
July 11, 2025 - The floatValue() method in Float Class is a built-in function in java that returns the value specified by the calling object as float after type casting.
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › Float.html
Float (Java Platform SE 6)
Compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the call: ... the value 0 if f1 is numerically equal to f2; a value less than 0 if f1 is numerically less than f2; and a value greater than 0 if f1 is numerically greater than f2. ... Submit a bug or feature For further API reference and developer documentation, see Java SE Developer Documentation.
🌐
DZone
dzone.com › coding › java › understanding floating-point precision issues in java
Understand Floating-Point Precision Issues in Java
September 12, 2024 - Inside float/double, we don't keep the binary array as it is. float/double follow the IEEE 754 standard.
🌐
Quora
quora.com › How-often-do-you-use-float-in-Java
How often do you use float in Java? - Quora
Answer (1 of 3): Only one very specific place: Storing floating point values to a file where file-size is an overarching concern. This is a very rare circumstance and most programmers will never encounter it. Even then, it does not have much space because it merely serializes some values with few...
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.lang.Float.html
Class java.lang.Float
extends Number The Float class provides an object wrapper for Float data values, and serves as a place for float-oriented operations. A wrapper is useful because most of Java's utility classes require the use of objects.