How to remove decimal part from a number in JavaScript
In this tutorial, we are going to learn about how to remove the decimal part from a number in JavaScript.
Consider we have the following number:
const num = 13.456
Now we need to remove the decimal part from the above number and print it like this:
13
Using the parseInt() function
In JavaScript, we can use the parseInt() function to remove the decimal parts from a number.
Here is an example:
const num = 109.42;
console.log(parseInt(num));
Output:
109
Alternatively, we can also use the Math.trunc()
function.
const num = 109.42;
console.log(Math.trunc(num));
Note: The Math.trunc()
function doesn’t support on Internet explorer.