toExponential()的差异

时间:2013-11-26 10:01:47

标签: javascript google-chrome firefox browser opera

这是Firefox中的错误吗?在其他浏览器中是否相同?这个地方有没有概述?有这种差异的任何充分理由吗?

             +---- 4 vs. 5
             |    
Firefox: 1.234e+4           (12345.0).toExponential(3);
Chrome : 1.235e+4           (12345.0).toExponential(3);
Opera  : 1.235e+4           (12345.0).toExponential(3);

以下是我对标准的解释:

From ECMA 262

x = 12345.0              // Let x be this Number value
ƒ = 3                    // Let ƒ be ToInteger(fractionalDigits)
s = ""                   // Let s be the empty String.

IF x != 0 && defined fractianalDigits THEN

    10׃ <= n < 10(ƒ + 1)    // Value of n

    n × 10(e - ƒ) - x        // Where closest to 0

    // If there are two such sets of e and n, 
    // pick the e and n for which n × 10e–ƒ is larger.

    300  <= n < 10.000

    1234 × 10(4 - 3) - 12345 = -5 => Firefox
    1235 × 10(4 - 3) - 12345 =  5 => Chrome / Opera

END IF

m = 1235                 // Let m be the String consisting of the digits of the 
                         // decimal representation of n.
a = 1                    // Let a be the first character of m
b = 235                  // Let b be the remaining characters of m
m = a + "." + b = 1.235  // Let m be the concatenation of a + "." + b
c = +                    // Let c = "+"
d = 4                    // Let d be the String consisting of 
                         // decimal digits of e.
m = m + "e" + c + d = 1.235e+4

return s + m

我离开了吗?

Linux的

  • Mozilla Firefox 24.0
  • Opera 12.16
  • Chrome 31.0.1650.48

0 个答案:

没有答案