-1
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 ?

kittu
  • 6,662
  • 21
  • 91
  • 185

4 Answers4

4

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.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75
3

12e-1 is scientific notation and means 12 * 10^-1 which is 1.2

Raniz
  • 10,882
  • 1
  • 32
  • 64
2

The e stands for 10^, or power of 10.

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

It is part of the syntax as defined in the Java Language Specification.

The Base for a Natural Logarithm (e) is available as Math.E (Eulers Number), or to use it as the base for an exponent, simple use Math.exp(-1). Note however that parameters and result types are double not float.

YoYo
  • 9,157
  • 8
  • 57
  • 74
2

You are confusing E notation with Euler's constant which is approx 2.71828.

Java number literals use e as E notation thus e in 12e-1F means float number 12*10^-1 which is 1.2.

Piotrek Bzdyl
  • 12,965
  • 1
  • 31
  • 49