JavaScript Number.EPSILON

The EPSILON property has a value of 252 that is approximately 2.2204460492503130808472633361816E-16.

It is a non-writable, non-enumerable, and non-configurable property.

Number.EPSILON can be used to test the equality of the floating-point numbers.

The syntax to access the EPSILON constant is:

Number.EPSILON

EPSILON is accessed using the Number class name.


Example: Using Number.EPSILON

value = Number.EPSILON;
console.log(value); // 2.220446049250313e-16

a = 0.1;
b = 0.2;
c = 0.3;

console.log(a + b == c); // false

console.log(a + b - c < value); // true

Output

2.220446049250313e-16
false
true

In JavaScript, due to how floating-point numbers are implemented, 0.1 + 0.2 is not exactly equal to 0.3. So, instead of using this ordinary checking method that does not work, we can instead check if their difference is smaller than Number.EPSILON.


Recommended Reading:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges