10

How do I create the number 1e6 with JavaScript?

var veryLargeNumber = //1e6
Cœur
  • 37,241
  • 25
  • 195
  • 267
TheBrent
  • 2,853
  • 3
  • 16
  • 14

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
  • 687,336
  • 108
  • 737
  • 1,005
2

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

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
1

Like you wrote above:

var veryLargeNumber = 1e6;//Equals to 1*10^6
Danilo Valente
  • 11,270
  • 8
  • 53
  • 67
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
  • 72,589
  • 19
  • 149
  • 183
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
  • 14,902
  • 10
  • 83
  • 103