Skip to content

JavaScript double to int | Example code

  • by

Use parseInt() function to convert double to int in JavaScript.The parseInt() function parses a string argument and returns an integer of the specified radix.

Example double to int in JavaScript

Simple example code.

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

Output:

JavaScript double to int

You can also use |.

var num = 2.9
console.log(num | 0); // 2

Converting a double to int in Javascript without rounding

Just use parseInt() and be sure to include the radix so you get predictable results:

parseInt(d, 10);

Do comment if you have any doubts or suggestions on this JS double to int topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading