Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What means an "E" or "e" character on larger fractional and float outputs?

Studying java, I have had an unexpected output for the following code:

int i = 1234567890;
float f = i;
int result = i - (int)f;

It's turned back as the value for the "result" variable the value -46, and I was expecting 0.0, believing that "float f = i" would be converted to 1234567890.0 instead of 1.23456794E9. Trying to understand it, I have noted that for the float type is only permitted, at most, 7 digits before the radix point, and, if is imputed a float with more that 7 digits before the radix point, compilers output a string that is composed with the radix point at the 2nd index place of that string and, at the penultimate index place, its returns a "E" or "e". What is it? What "e" means?

like image 644
Leandros López Avatar asked Apr 15 '15 12:04

Leandros López


1 Answers

That's scientific notation, in E notation. The E stands for exponent.

1.23456794E9 means 1.23456794 × 109 which is the same as 1234567940.

The limited precision of the float type means that the value is not the exact same value as the int. The scientific notation is used to show large or small values, it doesn't have anything to do with the loss of precision.

like image 136
Guffa Avatar answered Nov 15 '22 10:11

Guffa