'e' in javascript numbers

北城余情 提交于 2020-04-11 03:57:33

问题


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


回答1:


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)




回答2:


'e' in a number like that is the same as 'times 10 to the power of'

3.2e6 is 3.2x10^6




回答3:


4*10^4

if it was 4e5 would be = 4*10^5

etc



来源:https://stackoverflow.com/questions/39423555/e-in-javascript-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!