如何在 JavaScript 中创建数学数字 1e6?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11248323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 05:07:49  来源:igfitidea点击:

How can I create the mathematical number 1e6 in JavaScript?

javascriptmath

提问by TheBrent

How do I create the number 1e6 with JavaScript?

如何使用 JavaScript 创建数字 1e6?

var veryLargeNumber = //1e6

回答by Guffa

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);

回答by Mahmoud Gamal

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

它是按照你写的方式写的:var notVeryLargeNumber = 1e6

回答by Sirko

This works just fine for me

这对我来说很好用

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

outputs:

输出:

1000000

1000000

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

有关 JavaScript 中真正“大”数字的更多信息,请查看以下问题:

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

什么是 JavaScript 的 Max Int?在不损失精度的情况下,数字可以达到的最高整数值是多少?

回答by Danilo Valente

Like you wrote above:

就像你上面写的:

var veryLargeNumber = 1e6;//Equals to 1*10^6

回答by ptim

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

尽管 E 代表指数,但该符号通常被称为(科学)E 符号或(科学)e 符号

...

...

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.

因为像 10^7 这样的上标指数不能总是方便地显示,所以字母 E 或 e 经常被用来表示“乘以 10 的幂”(可以写成“× 10n”),后面是指数;换句话说,对于任意两个实数 m 和 n,使用“mEn”表示 m × 10n 的值。

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

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”开头,请使用指数表示法。后面跟着五个以上的零。例子:

> 0.0000003
3e-7

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

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



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

另外:如何将包含科学记数法的字符串转换为正确的 Javascript 数字格式

Number("4.874915326E7") //returns 48749153.26