10

How do I create the number 1e6 with JavaScript?

var veryLargeNumber = //1e6
Cœur
  • 34,719
  • 24
  • 185
  • 251
TheBrent
  • 2,853
  • 3
  • 15
  • 13

5 Answers5

24

Here are some different ways:

var veryLargeNumber = 1e6;

var veryLargeNumber = 1.0e+06;

var veryLargeNumber = 1000000;

var veryLargeNumber = 0xf4240;

var veryLargeNumber = 03641100;

var veryLargeNumber = Math.pow(10, 6);
Guffa
  • 666,277
  • 106
  • 705
  • 986
2

It is written the way you wrote it: var notVeryLargeNumber = 1e6.

Mahmoud Gamal
  • 75,299
  • 16
  • 132
  • 159
1

Like you wrote above:

var veryLargeNumber = 1e6;//Equals to 1*10^6
Danilo Valente
  • 11,037
  • 8
  • 52
  • 66
1

This works just fine for me

var veryLargeNumber = 1e6;
console.log( veryLargeNumber );

outputs:

1000000

For more information about really "large" numbers within JavaScript, have a look at this question:

What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?

Community
  • 1
  • 1
Sirko
  • 69,531
  • 19
  • 142
  • 174
1

For the curious, I went on a little learning safari...

Although the E stands for exponent, the notation is usually referred to as (scientific) E notation or (scientific) e notation

...

Because superscripted exponents like 10^7 cannot always be conveniently displayed, the letter E or e is often used to represent "times ten raised to the power of" (which would be written as "× 10n") and is followed by the value of the exponent; in other words, for any two real numbers m and n, the usage of "mEn" would indicate a value of m × 10n.

https://en.wikipedia.org/wiki/Scientific_notation#E_notation


Use exponential notation if number starts with “0.” followed by more than five zeros. Example:

> 0.0000003
3e-7

http://www.2ality.com/2012/03/displaying-numbers.html


Also: How to convert a String containing Scientific Notation to correct Javascript number format

Number("4.874915326E7") //returns 48749153.26
Community
  • 1
  • 1
ptim
  • 13,723
  • 9
  • 79
  • 94