parseFloat rounding

前端 未结 5 1208
太阳男子
太阳男子 2020-12-01 12:06

I have javascript function that automatically adds input fields together, but adding numbers like 1.35 + 1.35 + 1.35 gives me an output of 4.050000000000001, just as an exam

5条回答
  •  再見小時候
    2020-12-01 12:30

    You can use Math.round(total*100000000000)/100000000000; in the code. It will work for most of the cases

提交回复
热议问题