javascript large integer round because precision? (why?)

后端 未结 2 625
逝去的感伤
逝去的感伤 2020-11-28 16:41

if you type 78764357878563812 in chrome or in safari, then you get

If you do

for(var i = 0; i < 30; i++){console.log(i + \" == \" + 7876435787856         


        
2条回答
  •  借酒劲吻你
    2020-11-28 17:05

    There are no integers in Javascript.

    Numbers are double precision floating point, which gives you a precision of 15-16 digits. This is consistent with your results.

提交回复
热议问题