Search code examples
javascjp

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
    }
}

No idea how it prints the value 13.2. I some where read that e is 2.718 but what is this float f = 12e-1F; representing ?


Solution

  • The "e" is not the natural logarithm base, but short for "exponent". The number following the "e" is a power of ten, so 12e-1F is 1.2.