Scientific Notation – Understanding E-Notation

notation

Hey all I asked this over at StackOverflow =) and I got a good answer but I still have no idea whats going on. I want to know how the expression got to the answer and maybe the math behind how it was reasoned.. the steps if you would be so kind. The likelihood is I don't understand the equation.

I'm not a big maths person please be gentle :p

For all those playing along at home I'm reading Absolute Java 5th
Edition by Walter Savitch (Chapter 2 Page 66).

The Expression

double d = 12345.123456789;
System.out.printf("START%12.5e END %n", d);

The Answer

START 1.23451e+04END

I understand the basic principles of this printf method's arguments
for example I know the '%' represents the start of the parameters.
'12' is the number of spacing, '.5' is the times the decimal point
will move…. I see the decimal point has moved 4 places towards the
left… can someone explain the principles of e-notation. Also how
this expression came to this answer =).

As far as e-notation go's its meant to be scientific notation;

So like 5.89e-4 would mean 0.000589 (move the decimal place if minus
left if not move the decimal place right).

Best Answer

Used like this, eN (much more often EN) is just a symbol for $10^N$. It is used because scientific notation is convenient for large and small numbers and it avoids the need for superscripts. Superscripts used to be much more difficult to produce than they are today, and even today they are not easy in (some) word processors.

12.5e says allocate 12 spaces to the total output (including signs, e, etc.) and put 5 behind the decimal point. In your example there is room for a leading + sign (omitted) and eleven more characters. If the format were 12.3e you would probably get 123.451e+02 You need at least seven more total characters than decimals for the leading sign, the decimal point, e, the exponent sign, and two digits of exponent.

In your example, the decimal point moves by 4 places so there are the correct number of digits before it, then the e value was chosen to give the value 4