Categories
JavaScript Answers

How to truncate or round whole number in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *