科学记数法是解释为int还是float? [英] Is scientific notation interpreted as int or float?

查看:248
本文介绍了科学记数法是解释为int还是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 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 的类型为 float

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

这篇关于科学记数法是解释为int还是float?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆