Reputation: 2969
I need to understand the following:
when I type 4e4
in Google Chrome's console it returns 40000
.
Can anyone help me to understand what is e
in javascript numbers and what is the algorithm working for this?
Thanks in advance
Upvotes: 33
Views: 22346
Reputation: 5664
As this question is specifically about JavaScript I think it's good to have the examples from MDN here:
0e-5 // 0
0e+5 // 0
5e1 // 50
175e-2 // 1.75
1e3 // 1000
1e-3 // 0.001
1E3 // 1000
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates#exponentiation
Upvotes: 1
Reputation: 885
4e4
is a floating-point number representation.
It consists of:
It is also a way of how floating-point numbers are stored on the system. For instance, for single-precision we get: single-precision floating-point number representation
Together, it gives us:
-1^S * M * p^E
where p is the basis of the numerical system
So, in common sense, p can be anything so that 4e4
could be also 4 * 5^4
if p == 5
As we usually work with
decimal values
p is equal to 10
And as was answered before, 4e4 == 4 * 10^4
(as 4 is a decimal value in this case)
Upvotes: 17
Reputation: 2531
'e' in a number like that is the same as 'times 10 to the power of'
3.2e6 is 3.2x10^6
Upvotes: 14