1.精度问题
//number.epsilon属性(最小精度),两个数的差小于Number.epslion两个数相等 console.log(0.1 + 0.2)
2.解决
最小数解决:两个数的差小于Number.EPSILON,就认为两个数字是相等的
function eq(a, b) {
return Math.abs(a - b) < Number.EPSILON ?true : false
}
console.log(eq(0.1 + 0.2, 0.3)) //true
es对于数值扩展
最新推荐文章于 2024-07-12 09:36:48 发布