Related Articles

# How to check two numbers are approximately equal in JavaScript ?

• Last Updated : 31 Mar, 2021

Given two numbers and the task is to check the given numbers are approximately equal to each other or not. If both numbers are approximately the same then print true otherwise print false.

Example:

```Input:  num1 = 10.3
num2 = 10

Output: true```

Approach: To check the numbers are approximately the same or not, first, we have to decide the epsilon value. Epsilon is the maximum difference between two numbers, if the difference of the numbers is less than or equal to epsilon then the numbers are approximately equal to each other. So first we create a function named checkApprox which takes three arguments num1, num2, and epsilon. Now check the absolute difference of num1 and num2 is less than epsilon or not.

Example 1:

## Javascript

 ``

Output:

`true`

Example 2:

## Javascript

 ``

Output:

`true`

Example 3:

## Javascript

 ``

Output:

`false`

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up