floating point - Large numbers erroneously rounded in Javascript -


see code:

<html> <head>  <script src="http://www.json.org/json2.js" type="text/javascript"></script>  <script type="text/javascript">      var jsonstring = '{"id":714341252076979033,"type":"fuzzy"}';     var jsonparsed = json.parse(jsonstring);     console.log(jsonstring, jsonparsed);   </script> </head> <body> </body> </html> 

when see console in firefox 3.5, value of jsonparsed is:

object id=714341252076979100 type=fuzzy 

i.e number rounded. tried different values, same outcome (number rounded).

i don't rounding rules. 714341252076979136 rounded 714341252076979200, whereas 714341252076979135 rounded 714341252076979100.

edit: see first comment below. apparently not json, javascript number handling. question remains:

why happening?

what you're seeing here effect of 2 roundings. numbers in ecmascript internally represented double-precision floating-point. when id set 714341252076979033 (0x9e9d9958274c359 in hex), assigned nearest representable double-precision value, 714341252076979072 (0x9e9d9958274c380). when print out value, being rounded 15 significant decimal digits, gives 14341252076979100.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -