js 浮点数精度运算

 

<script>
  function withinErrorMargin (left, right) {
    return Math.abs(left - right) < Number.EPSILON * Math.pow(2, 2);
  };

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

 

posted @ 2020-06-29 15:20  本溢  阅读(78)  评论(0)    收藏  举报