当前位置: 代码迷 >> 综合 >> js误差检查函数
  详细解决方案

js误差检查函数

热度:26   发布时间:2024-01-29 01:14:17.0

    function withinErrorMargin (left, right) {

       return Math.abs(left - right) < Number.EPSILON * Math.pow(2, 2);

    }

    0.1 + 0.2 === 0.3 // false

    console.log(withinErrorMargin(0.1 + 0.2, 0.3)); // true

  相关解决方案