search

Home  >  Q&A  >  body text

javascript - In the for loop, why is the s output by the expression s+=0.01 not an arithmetic sequence?


Logically speaking, the output should be
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
1.00
1.01
Why is the output result like the picture above? Why do so many decimals suddenly appear?

仅有的幸福仅有的幸福2758 days ago647

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:40:57

    Accuracy error, use s.toFixed(2)

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:40:57

    Because js has errors when performing decimal operations

    reply
    0
  • Cancelreply