Open In App

JavaScript Number EPSILON Property

Last Updated : 15 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • It is a non-writable property which means this property is not writable.
  • It is a non-enumerable property which means this property is not countable.
  • It is a non-configurable property which means this property is not configurable.

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.

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:

  • Google Chrome 34 and above
  • Edge 12 and above
  • Firefox 25 and above
  • Opera 21 and above
  • Safari 9 and above
  • Internet Explorer not supported

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads