Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Number EPSILON Property

  • Last Updated : 18 May, 2021

This 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




<script>
  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);
</script>

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :