Primitive Data
12. Precision of Double
Answer:
There are nine decimal places of precision. Data type float
can't handle that.
(The compiler will round the number into a value that can fit in a float
).
Precision of Double
You might wish to argue that there are only five places used in the above number: the places used by the digits 1, 2, 3, 8, and 9. However, the four 0's in the middle do count. It takes bits to represent them, even if they are zeros.
Primitive data type double
uses 64 bits, and has a much greater range, -1.7E+308 to +1.7E+308. It also has a much greater precision: about 15 significant decimal digits.
Because of this, if you write a literal like 2.345 in a Java program, it will automatically be regarded as a double, even though a float might be good enough. The other numbers in the program might need to be double, so we might as well make them all double.
Question 12:
Do you suspect that characters are important enough to be one of the eight primitive data types?