Open In App

JavaScript Number EPSILON Property

EPSILON property shows the difference between 1 and the smallest floating point number which is greater than 1. When we calculate the value of EPSILON property we found it as 2 to the power -52 (2^-52) which gives us a value of 2.2204460492503130808472633361816E-16.

Syntax:



Number.EPSILON

Attribute:

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



Uses: This Number.EPSILON property is used to check whether floating-point numbers are equal or not.

In this EPSILON is accessed by calling the Number as a class name. 

Example: The following example demonstrates the Number.EPSILON property in JavaScript.




gfgval = Number.EPSILON;
// Output will be value of 2 to the power -52 (2^-52)
console.log(gfgval); 
  
x = 0.3;
y = 0.6;
z = 0.9;
// Output will be false
console.log(x + y == z);
  
// Output will be true
console.log(x + y - z < gfgval);

Output:

2.2204460492503130808472633361816E-16
false
true

There is a different way to execute floating-point numbers in JavaScript. Here 0.3 + 0.6 is not resulting exactly 0.9. So in place of using the usual testing procedure which will not work here, we can use JavaScript Number.EPSILON property to check that their difference should be smaller than the value of the Number.EPSILON.

Supported Browsers:

We have a complete list of JavaScript Number constructor, properties, and methods list, to know more about the numbers please go through that article.

Article Tags :