2

It seems a very simple question. the result of parseFloat in IE is different from the results in Chrome and FF. Here is the very simple code

<html>
    <script>
        var lat = parseFloat(" 25.482688176812758");
        alert(lat);
    </script>
    <body>
    </body>
</html>

then try to open it in IE the alert is 25.482688176812757 but in chrome and FF is 25.482688176812758

user3416285
  • 25
  • 1
  • 5

1 Answers1

0

It's the browser limitation of decimal places in implementation of Numbers.

A workaround is to use the library BigDecimal.

More on Floating-point cheat sheet for JavaScript.

Andre Figueiredo
  • 12,930
  • 8
  • 48
  • 74
  • 1
    While I'm not disagreeing with you -- I'm just curious. If the browsers all using IEEE 754 floating point, shouldn't all of the browsers have the same behavior? – Jeremy J Starcher Mar 13 '14 at 18:58
  • 1
    Should, but IE does not have the same behavior as others. It's tricky to work with this precision of data in JavaScript. i.e. Try to put in console Chrome/FF and IE this `25.482688176812758.toFixed(15) + '\n' + 25.482688176812758.toFixed(16);`. More, change 15 by 20 in both browsers.. – Andre Figueiredo Mar 13 '14 at 19:17