8e3评估的是多少?

[英]What number does 8e3 evaluate to?


I encountered this code today:

我今天遇到了这个代码:

b = setTimeout(function () {
    // do some javascript stuff here
}, 8e3)

The timeout is set to 8e3. What time does this equate to in milliseconds, and why would anyone choose this strange notation? The code appears to be fully functional.

超时设置为8e3。这段时间等于几毫秒,为什么有人会选择这种奇怪的符号?代码似乎功能齐全。

4 个解决方案

#1


35  

8e3 is eight times ten to the power of three, that is, 8000. This is called scientific (or exponential) notation. Just imagine the "e" stands for "*10^".

8e3是三次幂的八倍,即8000.这被称为科学(或指数)符号。试想一下,“e”代表“* 10 ^”。

In this case there isn't much point in using that notation, but once you start getting to larger numbers, exponential notation becomes more readable. To figure out how much "1000000000" is you'd have to count zeros, but 1e9 is immediately obvious.

在这种情况下,使用该表示法并没有多大意义,但是一旦开始获得更大的数字,指数表示法就会变得更具可读性。要计算出“1000000000”是多少,你必须计算零,但1e9立即显而易见。

#2


17  

This is called floating point notation or scientific notation. It is 8×10³, which is 8000 miliseconds. The e stands for 10th exponent. Let me give you some more examples:

这称为浮点符号或科学符号。它是8×10 3,即8000毫秒。 e代表第10个指数。让我举几个例子:

1e3    = 1000        // 1×10³
1e0    = 1           // 1×10⁰
1e-1   = 0.1         // 1×10⁻¹ -> Works also for the negatives
1.23e9 = 1230000000  // And really makes sense to shorten big numbers

There is also an wikipedia article on that topic: Scientific Notation

还有一篇关于该主题的维基百科文章:科学记谱法

#3


9  

8e3 is exactly 8000, so the time is exactly 8 seconds.

8e3正好是8000,所以时间恰好是8秒。

This could be chosen (eg. by some code minifiers) because it takes exactly 3 characters instead of 4 to represent 8000. Which means you gain 25% in terms of space in this single place :)

这可以选择(例如,通过一些代码缩小器),因为它只需要3个字符而不是4代表8000.这意味着你在这个单独的地方获得25%的空间:)

And this is not "strange" notation, it is just another way of expressing numbers: Floating point notation

这不是“奇怪的”符号,它只是表达数字的另一种方式:浮点符号

#4


9  

8*103 = 8000 ms which is 8 seconds

8 * 103 = 8000 ms,即8秒


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/02/07/fa13fe9ac6e9cebff841e9c1131d00cf.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号