How to remove decimal part from a number in JavaScript
In this post we will give you information about How to remove decimal part from a number in JavaScript. Hear we will give you detail about How to remove decimal part from a number in JavaScriptAnd how to use it also give you demo for it if it is necessary.
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 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.
Hope this code and post will helped you for implement How to remove decimal part from a number in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs