JavaScript Number.EPSILON Property
Number.EPSILON is the smallest gap between 1 and the next representable number. It's used as a tolerance when comparing decimal results.
Description
The Number.EPSILON static property is the difference between 1 and the smallest floating point number greater than 1. Because decimals like 0.1 can't be stored exactly, it is sometimes used as a tolerance when comparing calculated values: Math.abs(a - b) < Number.EPSILON. For numbers far from 1, a tolerance scaled to their size is more appropriate.
The gap between representable numbers grows as numbers get bigger, so a fixed epsilon only makes sense for values around 1. For larger values, scale the tolerance, as in Math.abs(a - b) < Number.EPSILON * Math.max(Math.abs(a), Math.abs(b)), or choose a tolerance suited to your data, such as 0.001 for measurements.
In many cases, rounding to a fixed number of decimal places before comparing, or working in whole units such as cents, is simpler and less error-prone than comparing floating point numbers with a tolerance. Like other static members of Number, it is called on the Number constructor itself, not on individual number values.
Syntax
Number.EPSILONValue
The difference between 1 and the smallest number greater than 1 that can be represented, about 2.22 × 10-16.
Example
Browser Support
The following information will show you the current browser support for the Number.EPSILON property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





