• 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...

Answer from Joey on Stack Overflow
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

🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › accelerated computing › cuda › cuda programming and performance
int32 Vs float32 performance difference and analysis advice - CUDA Programming and Performance - NVIDIA Developer Forums
July 31, 2017 - Hello, I wrote a simple matmul kernel for float and int and bench-marked on a Quadro K1200 with matrices of sizes 1024x1024x1024, 16384x128x128, 128x16384x128 ( NxKxM : C[NxM] = A[NxK] * B[KxM] ). Here’s the kernel, __global__ void matmul(int N, int K, int M, Type *C, Type *A, Type *B) { int i_idx = blockIdx.x, j_idx = blockIdx.y*BLK_SIZE + threadIdx.x; if( i_idx >= N || j_idx >= M ) return; int k; Type temp = C[i_idx*M+j_idx]; Type *A_ptr = A + i_idx*K + 0, *B_ptr = B + ...
Discussions

Why does float have a bigger range than int32?
Shouldn't float have an even smaller range because it can also hold decimal places? The way floating point numbers are implemented allows them to have the larger range, but, there is a price for this trade off. A single precision (32 bit) IEEE-754 float can only exactly represent integers with an absolute value less than 224. Beyond that, you end up with gaps in the number line where the integer has to be rounded to a value that the float can represent. Example: 224 is 16777216 in decimal. Encoded as a float, this has the value 0x4b800000. The next integer value (16777217) encoded as a float is... also 0x4b800000. If you continue, you'll find that 16777218 can be represented exactly (0x4b800001), but 16777219 cannot. As the values grow past 224, the gaps between exact representations grow as well. More on reddit.com
🌐 r/AskProgramming
3
1
September 13, 2015
integers - Why short and long and double and similar instead of unambigous width types such as int16 or int64 or float64? - Programming Language Design and Implementation Stack Exchange
But in Java all are guaranteed to be a certain width as far as I can tell. Though removing ambiguity is an advantage of having the width in the type names, so are there other reasons why I would have: short int long float double instead of int16 int32 int64 float32 or float64? More on langdev.stackexchange.com
🌐 langdev.stackexchange.com
c - Size of int and float - Stack Overflow
I have a question about the ranges of ints and floats: If they both have the same size of 4 bytes, why do they have different ranges? More on stackoverflow.com
🌐 stackoverflow.com
variable attributes: float32 vs float64, int32 vs int64
When I define my variables as data_type of "f" or "f4", these should be 32-bit floating-point decimals. However, when defining a variable attribute whose value is a floating-poi... More on github.com
🌐 github.com
2
May 7, 2019
🌐
Xojo Programming Forum
forum.xojo.com › general
Single Vs Int32 - General - Xojo Programming Forum
September 5, 2017 - I’m porting some Java code where most of the values are declared a type float. I think Java floats are single-precision 32-bit IEEE 754 floating point numbers. Up until now I’ve been using the Xojo Double type in the por…
🌐
Reddit
reddit.com › r/askprogramming › why does float have a bigger range than int32?
r/AskProgramming on Reddit: Why does float have a bigger range than int32?
September 13, 2015 -

float (32 Bit): -3,4E+38 to +3,4E+38

int (32 Bit): -2.147.483.648 to +2.147.483.647

Why is it like that? Shouldn't float have an even smaller range because it can also hold decimal places?

🌐
Sololearn
sololearn.com › en › Discuss › 3057798 › difference-between-float-and-int
Difference between float and int | Sololearn: Learn to code for FREE!
July 9, 2022 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Quora
quora.com › What-is-the-difference-between-a-float-and-an-int-in-Java
What is the difference between a float and an int in Java? - Quora
Answer (1 of 6): Both primitive types ‘float’ and ‘int’ use 32 bits to represent a number. However, ‘int’ can only represent integer numbers, that is positive and negative whole numbers, including 0. For a regular ‘int’, the minimum value is -2^31 and the maximum value is 2^31–1. ...
🌐
Jeskola
forums.jeskola.net › board index › buzz › users
Hard disk recorder modes, int32 vs. float32? - buzz forums
What's the difference with HD recorder modes like int32 and float32? ---edit--- Well, both work and i don't get any difference with them -at least not anything that i could hear.. so i guess it doesn't matter. That's why i ended asking it now, after pretty long use..
🌐
Wikipedia
en.wikipedia.org › wiki › Single-precision_floating-point_format
Single-precision floating-point format - Wikipedia
3 weeks ago - Single-precision floating-point format (sometimes called FP32, float32, or float) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide range of numeric values by using a floating radix point. A floating-point variable can represent a wider range of ...
Find elsewhere
🌐
javathinking
javathinking.com › blog › what-is-the-difference-between-the-float-and-integer-data-type-when-the-size-is-the-same
Float vs Integer Data Type: What's the Difference When Size is the Same? — javathinking.com
If you store 16777217 (2²⁴ + 1) in a float32, it becomes 16777216—a silent error! If you exceed int32’s range (e.g., 2e9 in a 32-bit int), you’ll get overflow (undefined behavior in languages like C++).
Top answer
1 of 3
14

Believe it or not, the original idea in C was that you weren't supposed to worry about the size, and other languages made shortly thereafter followed suit. The idea was "use int for integers, float for decimals, and let the compiler decide the side". Obviously, that hasn't been the reality. Everybody is constantly working around this, most large C programs use typedefs to get precise sizes, and the terminology is largely considered a misfeature.

2 of 3
9

C's choice to make integer widths depend on the hardware (or, strictly speaking, the compiler's choice ─ but in practice, compilers choose based on the hardware) means these types are "leaky abstractions". They don't save the user from having to think about the lower-level details.

In contrast, Java's primitive types are "safe abstractions" ─ you get the same behaviour regardless of the machine architecture that will end up running your program. But you still need to know the number of bits for each type, because these aren't included in the type names. Probably Java's reason for keeping the names int, long and so on is because the designers were explicitly trying to keep their language familiar to C programmers, in order to encourage adoption. (Java has the same motivation for borrowing other things from C's syntax, including that you can declare array variables like int x[]; instead of int[] x;.)

A downside of type names like uint32 or float64 is that they are longer, and take up more space; this particularly matters for the fundamental primitive types of the language, which users will have to type and read over and over again. Rust's solution here is a good one: the primitive types u32, i32, f32, u64, i64, f64 and so on have explicit bit-widths in their names, while also being short; and if the programmer wants a platform-dependent integer they can use usize or isize. Sure, this means the programmer needs to know that i means integer and f means floating-point number, but that's less to remember than the widths of every type, and it's an abbreviation rather than an arbitrary name like "short" or "long".

🌐
Alammori
alammori.com › benchmarks › int32-vs-int64-performace
Int32 VS Int64 performance - Hasan Al-Ammori Blog
April 5, 2022 - Having compared int to float arithmetics, one should wonder: is there a similar difference between Int32 and Int64? Let’s find out!
Top answer
1 of 6
23

They are totally different - typically int is just a straightforward 2's complement signed integer, while float is a single precision floating point representation with 23 bits of mantissa, 8 bits exponent and 1 bit sign (see http://en.wikipedia.org/wiki/IEEE_754-2008).

2 of 6
18

They have different ranges of values because their contents are interpreted differently; in other words, they have different representations.

Floats and doubles are typically represented as something like

+-+-------+------------------------+
| |       |                        |
+-+-------+------------------------+
 ^    ^                ^
 |    |                |
 |    |                +--- significand
 |    +-- exponent
 |
 +---- sign bit

where you have 1 bit to represent the sign s (0 for positive, 1 for negative), some number of bits to represent an exponent e, and the remaining bits for a significand, or fraction f. The value is being represented is s * f * 2e.

The range of values that can be represented is determined by the number of bits in the exponent; the more bits in the exponent, the wider the range of possible values.

The precision (informally, the size of the gap between representable values) is determined by the number of bits in the significand. Not all floating-point values can be represented exactly in a given number of bits. The more bits you have in the significand, the smaller the gap between any two representable values.

Each bit in the significand represents 1/2n, where n is the bit number counting from the left:

 110100...
 ^^ ^
 || |  
 || +------ 1/2^4 = 0.0625
 || 
 |+-------- 1/2^2 = 0.25
 |
 +--------- 1/2^1 = 0.5
                    ------
                    0.8125

Here's a link everyone should have bookmarked: What Every Computer Scientist Should Know About Floating Point Arithmetic.

🌐
Hacker News
news.ycombinator.com › item
At least as far as int32 vs float32 goes, surprisingly float is easier to make f... | Hacker News
October 18, 2021 - While floating point numbers can be cleanly split into a mantissa and exponent, adding floats requires shifting the exponent, which can be an expensive operation. Each portion of a floating point arithmetic operation is also implemented with integer arithmetic, which limits the performance spread.
🌐
GitHub
github.com › Unidata › netcdf4-python › issues › 926
variable attributes: float32 vs float64, int32 vs int64 · Issue #926 · Unidata/netcdf4-python
May 7, 2019 - variable attributes: float32 vs float64, int32 vs int64#926 · Copy link · ghost · opened · on May 7, 2019 · When I define my variables as data_type of "f" or "f4", these should be 32-bit floating-point decimals. However, when defining a variable attribute whose value is a floating-point via setncattr, the result is a 64-bit floating-point ("double").
Author   ghost
🌐
John D. Cook
johndcook.com › blog › 2025 › 06 › 27 › most-ints-are-not-floats
Most machine integers are not machine floats
June 29, 2025 - Most int32 numbers cannot be represented exactly by a float32. All int32 numbers can be represented approximately as float32 numbers, but usually not exactly.
🌐
Sololearn
sololearn.com › en › Discuss › 2682964 › golang-int8-int16-int32-float32-
Golang int8, int16, int32, float32 .... | Sololearn: Learn to code for FREE!
because sometimes int32 or below is enough (and it could make a memory footprint very different for large dataset).
🌐
Quora
quora.com › Why-do-both-float-and-int-in-Java-have-the-same-storage-size-but-different-min-and-max-values
Why do both float and int in Java have the same storage size but different min and max values? - Quora
Answer (1 of 5): Because even though they have different ranges, the possible number of values they can represent are identical. Both are 32-bit. This means that the number of values that they can represent is 2^{32}=4294967296. For an [code ]int[/code], half of those values are for negative int...
🌐
Cantabile Community
community.cantabilesoftware.com › t › difference-between-32-bit-fixed-integer-and-32-bit-floating-point › 186
Difference between 32-bit fixed integer and 32-bit floating point - Cantabile Community
November 30, 2015 - I had some recordings in 24-bit, 48000 sample rate, but now have the setup using 44100 to save CPU load. When I played them back in the media player, those were all distorted unless I changed my audio card back to 48000. While sleuthing that out, as I knew that wasn’t supposed to be the case, ...
🌐
Google Groups
groups.google.com › g › protobuf › c › XVr45yvRzkA
uint32 vs int32: who is the most efficient? (Java)
(the same is for int64 and uint64) I quote below the code of writeInt32NoTag and writeUInt32NoTag methods: public void writeUInt32NoTag(final int value) throws IOException { writeRawVarint32(value); } public void writeInt32NoTag(final int value) throws IOException { if (value >= 0) { writeRawVarint32(value); } else { // Must sign-extend. writeRawVarint64(value); } } *************** INT32 ******************* Bytes int32 1 0 <= value <= 127 2 128 <= value <= 16383 3 16384 <= value <= 2097151 4 2097152 <= value <= 268435455 5 268435455 < value 10 value < 0 Bytes sint32 1 -64 <= value <= 63 2 -819
🌐
Sololearn
sololearn.com › en › Discuss › 32322 › float-vs-int
Float vs. int? | Sololearn: Learn to code for FREE!
When testing some script, I would get an error message every time I wrote something like float x = 3/1.5; or float x = 2.6; but not float x = 3/2; however, 3/2 would com