Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'e' in javascript numbers

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

like image 420
Bhupi Avatar asked Sep 10 '16 07:09

Bhupi


People also ask

What is E in number JavaScript?

The Math. E property represents Euler's number, the base of natural logarithms, e, which is approximately 2.718. Math.E = e ≈ 2.718.

How do I get E in JavaScript?

To get Euler's constant value in JavaScript, use the Math E property. This is a Euler's constant and the base of natural logarithms, approximately 2.718.

What is number () in JavaScript?

Javascript Number() Function object: This parameter holds the objects that will be converted any type of javascript variable to number type. Return Values: Number() function returns the number format for any type of javascript variable. Example 2: Not a number is returned by the compiler.

How do you do scientific notation in JavaScript?

JavaScript converts any floating-point value with at least six trailing zeros into an annotation by default. 10e1 is 100 and 10e-1 is 1 . You can easily expand this to see that 10eN * 10e-N is always 100 . If you want true scientific notation, as in 1 * 10^2 , you want 1e12 and 1e-12 .


1 Answers

4e4 is a floating-point number representation. It consists of:

  1. Sign - S(+ or -)
  2. Mantissa - M(some number, normalized: 1.x where x is some sequence of digits)
  3. Exponent - E(represents a power of 10 that is Mantissa(M) multiplied with)

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)

like image 146
andrgolubev Avatar answered Nov 06 '22 12:11

andrgolubev