javascript number literal using exponent -
console.log(2e-12); // returns 2e-12 console.log(2e12); // returns 2000000000000 why line 1 return 2e-12 , not same line two. illegal way of using exponent?
from ecmascript specification of tostring applied number type:
7. if 0 < n ≤ 21, return string consisting of significant n digits of decimal representation of s, followed decimal point ‘.’, followed remaining k−n digits of decimal representation of s.
8. if −6 < n ≤ 0, return string consisting of character ‘0’, followed decimal point ‘.’, followed −n occurrences of character ‘0’, followed k digits of decimal representation of s.
9. otherwise, if k = 1, return string consisting of single digit of s, followed lowercase character ‘e’, followed plus sign ‘+’ or minus sign ‘−’ according whether n−1 positive or negative, followed decimal representation of integer abs(n−1) (with no leading zeroes).
n exponent of number. says if exponent between -7 , 21 number should displayed normally, otherwise exponential notation should used.
Comments
Post a Comment