floatstores floating-point values, that is, values that have potential decimal placesintonly 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...
floatstores floating-point values, that is, values that have potential decimal placesintonly 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...
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
Why does float have a bigger range than int32?
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
c - Size of int and float - Stack Overflow
variable attributes: float32 vs float64, int32 vs int64
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?
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.
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".
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).
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.