Large numbers erroneously rounded in JavaScript

后端 未结 6 1115
夕颜
夕颜 2020-11-21 23:58

See this code:



        
6条回答
  •  一向
    一向 (楼主)
    2020-11-22 00:31

    What you're seeing here is actually the effect of two roundings. Numbers in ECMAScript are internally represented double-precision floating-point. When id is set to 714341252076979033 (0x9e9d9958274c359 in hex), it actually is assigned the nearest representable double-precision value, which is 714341252076979072 (0x9e9d9958274c380). When you print out the value, it is being rounded to 15 significant decimal digits, which gives 14341252076979100.

提交回复
热议问题