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.
Contact Us