这些数字是什么,它们的类型是什么?
What are those numbers and what is their type?
好的,我在这里得到了几个值:
'F', 0xf, 070, 70L, 77e-1f, 7.7f, 7.77e1, 77.7
我知道 'F'
是 char
而 70L
的类型是 long
。另外,我知道 0xf
是十六进制(对吗?)而 070
是八进制。但是那些其他数字是什么?为什么他妈的是 77.7
double
而不是 float
?
你自己没有解释的唯一两个:
7.7f
f 的意思是 float - 它表明这不应该是 double 字面量,而是一个 float 字面值!您会看到,默认情况下任何 "floating point" 字面值都自动属于 double 类型,您需要 "f" 才能强制执行 "smaller" 浮点类型。
和
77e-1f
使用的是科学记数法,详见here示例。
And why the hell is 77.7 double and not float as well?
Float 数字最后必须用 f
表示,但 double 数字不需要 d
最后。
77e-1f
是 float 数 77
的 10^-1
次方,因此等于 7.7
.
同7.77e1
== 77.7
在 Java 中,包含点的数字文字默认为双精度类型。如果你想要一个浮动,你需要附加 f
.
包含e
的数字是指数或科学计数法,这里不做解释,因为它与编程无关。
您要找的是this
- 关于
77.7
:
A floating-point literal is of type float if it ends with the letter F
or f; otherwise its type is double and it can optionally end with the
letter D or d.
0xf
不是 hex
类型。没有类型hex
。它只是一个用十六进制写成的 int
。就像070
是一个用八进制写成的int
。
文字 77e-1f
显然是一个浮点数,因为它以 f
结尾。
e
是 exponent
即 77e-1f
实际上是 77 * 10^(-1)
或 7.7
。文字 7.77e1
是双精度的,原因与 77.7
是双精度的相同,只是 7.77e1
等于 7.77 * 10 ^ 1
= 77.7
.
77e-1 means this: 77
is number-multiplier, e
(or E
) means base 10
, and -1
means exponent.
所以结果是 77
by (10
powered by -1
), 或者 77
by .1
, i. e. 7.7
这种表示法的名称是 scientific 或 logarithmic,适用于非常大或非常小的数字,例如。 G。 1 million = 1.000.000
可以表示为 1e6
好的,我在这里得到了几个值:
'F', 0xf, 070, 70L, 77e-1f, 7.7f, 7.77e1, 77.7
我知道 'F'
是 char
而 70L
的类型是 long
。另外,我知道 0xf
是十六进制(对吗?)而 070
是八进制。但是那些其他数字是什么?为什么他妈的是 77.7
double
而不是 float
?
你自己没有解释的唯一两个:
7.7f
f 的意思是 float - 它表明这不应该是 double 字面量,而是一个 float 字面值!您会看到,默认情况下任何 "floating point" 字面值都自动属于 double 类型,您需要 "f" 才能强制执行 "smaller" 浮点类型。
和
77e-1f
使用的是科学记数法,详见here示例。
And why the hell is 77.7 double and not float as well?
Float 数字最后必须用 f
表示,但 double 数字不需要 d
最后。
77e-1f
是 float 数 77
的 10^-1
次方,因此等于 7.7
.
同7.77e1
== 77.7
在 Java 中,包含点的数字文字默认为双精度类型。如果你想要一个浮动,你需要附加 f
.
包含e
的数字是指数或科学计数法,这里不做解释,因为它与编程无关。
您要找的是this
- 关于
77.7
:
A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d.
0xf
不是hex
类型。没有类型hex
。它只是一个用十六进制写成的int
。就像070
是一个用八进制写成的int
。文字
77e-1f
显然是一个浮点数,因为它以f
结尾。e
是exponent
即77e-1f
实际上是77 * 10^(-1)
或7.7
。文字7.77e1
是双精度的,原因与77.7
是双精度的相同,只是7.77e1
等于7.77 * 10 ^ 1
=77.7
.
77e-1 means this:
77
is number-multiplier,e
(orE
) meansbase 10
, and-1
means exponent.
所以结果是 77
by (10
powered by -1
), 或者 77
by .1
, i. e. 7.7
这种表示法的名称是 scientific 或 logarithmic,适用于非常大或非常小的数字,例如。 G。 1 million = 1.000.000
可以表示为 1e6