如果我使用科学符号(例如1e9)在我的代码中编码一个数字,该数字的类型将是(int,long,float,double ..)?
当有效位数或指数为浮点数时,显然不能是整数,但在上述情况下呢?
解决方法@H_403_6@
e使它成为一个浮点文字.从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).
因此,1e9类型为double,为1e9d.另一方面,1e9f是浮点型.
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).
因此,1e9类型为double,为1e9d.另一方面,1e9f是浮点型.