Why is 9999999999999999 converted to 10000000000000000 in JavaScript?

后端 未结 5 2087
遥遥无期
遥遥无期 2020-11-30 03:45

Can any one explain to me why 9999999999999999 is converted to 10000000000000000?

alert(9999999999999999); //10000000000000000

http://jsfid

5条回答
  •  粉色の甜心
    2020-11-30 04:20

    1. JavaScript only has floating point numbers, no integers.

    2. Read What Every Computer Scientist Should Know About Floating-Point Arithmetic.

      Summary: floating point numbers include only limited precision, more than 15 digits (or so) and you'll get rounding.

提交回复
热议问题