Question:
What is the difference between a float and a double in Java?
Answer:
The double data type is a double-precision 64-bit IEEE 754 floating point.
The float data type is a single-precision 32-bit IEEE 754 floating point.
See: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
The float data type is a single-precision 32-bit IEEE 754 floating point.
See: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Code:
public class Ranges { public static void main(String[] args) { // double min / max. System.out.println(" Double.MAX_VALUE: " + Double.MAX_VALUE); System.out.println(" Double.MIN_NORMAL: " + Double.MIN_NORMAL); // float min / max. System.out.println(" Float.MAX_VALUE: " + Float.MAX_VALUE); System.out.println(" Float.MIN_VALUE: " + Float.MIN_VALUE); } }
Output:
$ java Ranges Double.MAX_VALUE: 1.7976931348623157E308 Double.MIN_NORMAL: 2.2250738585072014E-308 Float.MAX_VALUE: 3.4028235E38 Float.MIN_VALUE: 1.4E-45