Sometimes, we want to round to whole numbers in JavaScript.
In this article, we’ll look at how to round to whole numbers in JavaScript.
How to round to whole numbers in JavaScript?
To round to whole numbers in JavaScript, we can use some Math
methods.
For instance, we write
const ceiling = Math.ceil(num);
const floor = Math.floor(num);
const rounded = Math.round(num);
to call Math.ceil
to get the ceiling of number num
.
We call Math.floor
to get the floorof number num
.
And we call Math.round
to get num
rounded with banker’s rounding.
Conclusion
To round to whole numbers in JavaScript, we can use some Math
methods.