科学记数法是解释为int还是float? [英] Is scientific notation interpreted as int or float?
问题描述
如果我使用科学记数法(例如 1e9
)对我的代码中的数字进行硬编码,那么该数字的类型是什么(int,long,float,double .. )?
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?
推荐答案
e
使其成为浮点文字。来自JLS(§3.10.2。浮点文字):
The e
makes it a floating-point literal. From the JLS (§3.10.2. Floating-Point Literals):
浮点文字的类型为
float
如果后缀为ASCII字母F
或f
;否则其类型为double
,并且可以选择以ASCII字母后缀D
或d
(§4.2.3)。
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
的类型为 float
。
Therefore, 1e9
of type double
, as is 1e9d
. On the other hand, 1e9f
is of type float
.
这篇关于科学记数法是解释为int还是float?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!