Sometimes, we want to truncate or round whole number in JavaScript.
In this article, we’ll look at how to truncate or round whole number in JavaScript.
How to truncate or round whole number in JavaScript?
To truncate or round whole number in JavaScript, we can use the Math.trunc
method.
For instance, we write
const num = -2147483649.536;
const result = Math.trunc(num);
to call Math.trunc
with num
to return a number with the decimal part removed.
Conclusion
To truncate or round whole number in JavaScript, we can use the Math.trunc
method.