How to use Math.round() Method In Javascript

Math.round() method is used to round a number to its nearest integer. If the fractional part of the number is greater than or equal to .5, the argument is rounded to the next higher integer. 

Example: The below code illustrates how to remove the decimal part of a number.

Javascript




console.log(Math.round(42.80));
console.log(Math.round(0.80));
console.log(Math.round(-89.70));


Output:

43
1
-90


How to Remove the Decimal Part of a Number in JavaScript ?

The decimal portion of a number in JavaScript can be removed through various methods, including the Math. trunc( ) method, Math. floor( ) method, Math. ceil( ) method, and Math. round( ) method.

Similar Reads

Syntax

Math.trunc(11.5) // Output: 11Math.floor(12.5) // Output: 12Math.ceil(15.5) // Output: 15Math.round(-20.5) // Output: -20...

Using Math.trunc() Method

The Javascript  Math. trunc() method is used to return the integer part of a floating-point number by removing the fractional digits....

Using Math.floor() Method

...

Using Math.ceil() Method

Math.floor() method is used to round off the number to its nearest integer and returns the smallest integer greater than or equal to the given number....

Using Math.round() Method

...

Contact Us