Maximum values of int and float data types
Dear all,
The numbers are stored in binary format in any computer language.Both int and float data types have size 4 bytes (32 bits).
If that be the case,why int type variable can store maximum number 2147483647 while float can store up to 3.4028235E38 ? If both data types store numbers in same number of bits (32 bits),ideally maximum number that can be stored should also be same.But that is not the case. Could anybody please let me know why is it so?
Consider the following simple code.
public class MinMax{
public static void main(String args[]){
System.out.println(Float.SIZE);
System.out.println(Float.MAX_VALUE);
System.out.println();
System.out.println(Integer.SIZE);
System.out.println(Integer.MAX_VALUE);
}
}
The output of the code is as follows
32
3.4028235E38
32
2147483647
Regards,
Vishram
|