epsilon来自拉丁字母ɛ, ɛ在计算机科学中表示空字符串或者数值型态的精确度

这是个很经典的题

console.log( 0.1 + 0.2 == 0.3)

返回值为false

因为根据浮点数的定义,非整数的Number类型无法使用==或者===来进行比较
这里涉及到计算机原理,具体参考 https://juejin.im/post/5aa1395c6fb9a028df223516

说一说这里错误的不是结论而是过程
ES6 在Number对象上面,新增一个极小的常量Number.EPSILON。
根据规格,它表示 1 与大于 1 的最小浮点数之间的差。
如果使用以下方式 则返回true

console.log( Math.abs(0.1 + 0.2 - 0.3) <= Number.EPSILON);
Last modification:August 26, 2019
If you think my article is useful to you, please feel free to appreciate