Monday, November 5, 2012

Float vs. Double (float)

There are two kinds of floating-point types, float and double, which represent single- and double-precision numbers, respectively. Their width and ranges are shown here:

NameWidth in BitsRange
double641 .7e–308 to 1.7e+308
float323 .4e–038 to 3.4e+038
package primitiveData;

public class PrimitiveDataTest {
public static void main(String[] args) {
float f = 1.23456789012345678901234567890f; //end with "f" to indicate this is a float type, otherwise, it is a double type by default
double d = 1.23456789012345678901234567890;
System.out.println(f);
System.out.println(d);
}
}

OutPut:
1.2345679
1.2345678901234567

No comments:

Post a Comment