Reputation: 81
What is the data type for the number 9.6352
in Java?
Actually if I postfix the number with 'd' or 'f'. then it will be quite easy to decide. But if I leave it as alone, then which will be the default type of the number in java?
Upvotes: 5
Views: 1124
Reputation: 206679
Go check out the JLS section on floating point literals (§3.10.2):
A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d.
So it's a double if it's not suffixed.
Upvotes: 10
Reputation: 533482
For you interest;
0xD
is 13, 0xF
is 150D
is (double) 0
and 0F
is (float) 0
. Upvotes: 2
Reputation: 395
By default, any floating point data type without 'f' or 'F' postfixed, is considered as of type double
.
Since the given number doesn't end with 'f'/'F', it is of type double
.
We can optionally add 'd' or 'D' at the end to mark it as a double
type, but again, it is optional.
Upvotes: 8