JavaScript 判断两个数字相等(在误差范围内) - acwong00/blog GitHub Wiki

function numbersCloseEnoughToEqual(n1, n2) {
  return Math.abs(n1 - n2) < Number.EPSILON
}

Number.EPSILON 为常量,值为 2^-52