If I hardcode a number in my code using the scientific notation (e.g. 1e9
) what will the type of that number be (int, long, float, double..)?
When the significand or the exponent are floating point numbers it can't be an integer obviously, but what in the above case?
The e
makes it a floating-point literal. From the JLS (§3.10.2. Floating-Point Literals):
A floating-point literal is of type
float
if it is suffixed with an ASCII letterF
orf
; otherwise its type isdouble
and it can optionally be suffixed with an ASCII letterD
ord
(§4.2.3).
Therefore, 1e9
of type double
, as is 1e9d
. On the other hand, 1e9f
is of type float
.