如果我使用科学符号(例如1e9)在我的代码中编码一个数字,该数字的类型将是(int,long,float,double ..)?
当有效位数或指数为浮点数时,显然不能是整数,但在上述情况下呢?
解决方法
e使它成为一个浮点文字.从JLS(
§3.10.2. Floating-Point Literals):
A floating-point literal is of type
floatif it is suffixed with an ASCII letterForf; otherwise its type isdoubleand it can optionally be suffixed with an ASCII letterDord(§4.2.3).
因此,1e9类型为double,为1e9d.另一方面,1e9f是浮点型.
