我尝试将小数乘以倍数来修复浮点数的bug:Math.plus=(...numbers)=>{returnnumbers.reduce((acc,cur)=>(acc*1000+cur*1000)/1000);};但发现有的数能计算正确,有的还是会出现浮点数bug:console.log(Math.plus(16.141,0.016));//16.156999999999996console.log(Math.plus(16.201,0.016));//16.217console.log((16141+16)/1000);//16.157请问如何解决这个问题呢?
相关分类