Number.EPSILON

The smallest interval between two representable numbers, useful for float comparisons.

Since ES2015 Spec ↗

Syntax

Number.EPSILON

Returns

number — Approximately 2.220446049250313e-16 (2^-52).

Examples

console.log(0.1 + 0.2 === 0.3);
Output
false
console.log(Math.abs(0.1 + 0.2 - 0.3) < Number.EPSILON);
Output
true

Notes

Use it as a tolerance when comparing floating-point results that may differ by tiny rounding errors. For large magnitudes a relative epsilon is more appropriate than this absolute value.

Browser & runtime support

EnvironmentSince version
chrome 34
firefox 25
safari 9
edge 12
node 0.12

See also