Is scientific notation interpreted as int or float?

int, java, scientific-notation

Solution

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 letter `F` or `f`; otherwise its type is `double` and it can optionally be suffixed with an ASCII letter `D` or `d` (§4.2.3).

Therefore, `1e9` of type `double`, as is `1e9d`. On the other hand, `1e9f` is of type `float`.

Problem

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?

Original source