Skip to content

Convert a float number to a whole number in JavaScript

Find out how to convert a float number to a whole number in JavaScript. To do this we can use library methods in Math library.

var floatNum = 2.5;
console.log(Math.trunc(floatNum)); //2
console.log(Math.ceil(floatNum)); //3
console.log(Math.floor(floatNum)); //2
console.log(Math.round(floatNum)); //3

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.