float with 'e' 如何在变量声明中工作

How float with 'e' will work in a variable declaration

public class TypeConversion3 {

    public static void main(String[] args) {
        float f = 12e-1F;
        final long l = 12L;
        f = f + l;
        System.out.println(f); //prints 13.2
    }
}

不知道它如何打印值 13.2。我在某些地方读到 e 是 2.718,但是这个 float f = 12e-1F; 代表什么?

"e"不是自然对数的底数,而是"exponent"的简写。 "e" 后面的数字是 10 的幂,所以 12e-1F 是 1.2。

12e-1 是 scientific notation 意思是 12 * 10^-1 即 1.2

e 代表 10^,或 10 的幂。

12E-1F = 12.0 * 10 ^ -1 = 12.0 / 10 = 1.2

它是 Java Language Specification 中定义的语法的一部分。

自然对数 (e) 的底数可用 Math.E (Eulers Number), or to use it as the base for an exponent, simple use Math.exp(-1)。但是请注意,参数和结果类型是 double 而不是 float.

你混淆了 E notation with Euler's constant,它大约是 2.71828。

Java 数字文字使用 e 作为 E 表示法 12e-1F 中的 e 表示 float number 12*10^-11.2.