简体   繁体   English

添加十进制数字时parseFloat行为异常

[英]parseFloat acts weird when adding decimal numbers

在此处输入图片说明

Adding parseFloat(33.3) + 37.4 gives 70.699999999 in chrome console 在Chrome控制台中添加parseFloat(33.3) + 37.4得到70.699999999

Can anyone explain me why this is happening and how to overcome this problem. 谁能解释我为什么会这样以及如何解决这个问题。

一种快速的解决方案是四舍五入到指定的小数位数:

(33.3 + 37.4).toFixed(3); // would result in 70.700

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM