Categories
JavaScript Answers

How to convert a double to an int in JavaScript without rounding?

Spread the love

Sometimes, we want to convert a double to an int in JavaScript without rounding.

In this article, we’ll look at how to convert a double to an int in JavaScript without rounding.

How to convert a double to an int in JavaScript without rounding?

To convert a double to an int in JavaScript without rounding, we can use the parseInt function.

For instance, we write

const num = 2.9;
console.log(parseInt(num, 10));

to call parseInt with num and radix 10 to return an integer part of num as the value.

As a result, we see 2 logged from the console log.

Conclusion

To convert a double to an int in JavaScript without rounding, we can use the parseInt function.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.