Number.EPSILON property represents the difference between 1 and the smallest floating point number greater than 1.

You do not have to create a Number object to access this static property (use Number.EPSILON ).

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

特性属性在 Number.EPSILON
可写 no
可枚举 no
可配置 no

描述

EPSILON property has a value of approximately 2.2204460492503130808472633361816E-16 ,或 2 -52 .

Polyfill

if (Number.EPSILON === undefined) {
    Number.EPSILON = Math.pow(2, -52);
}
					

范例

Testing equality

x = 0.2;
y = 0.3;
z = 0.1;
equal = (Math.abs(x - y + z) < Number.EPSILON);
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Number.EPSILON' in that specification.

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
EPSILON Chrome 34 Edge 12 Firefox 25 IE No Opera 21 Safari 9 WebView Android ≤37 Chrome Android 34 Firefox Android 25 Opera Android 21 Safari iOS 9 Samsung Internet Android 2.0 nodejs 0.12

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: