Menu Home


Hi everyone, and welcome to another exciting adventure in Boring JavaScript! Today, we take a look at the Math.floor() method.

Don’t like to read? Then view our video.

Get Off That Floor

The Math.floor() method returns the largest integer less than or equal to a number. For positive numbers, this will be the same as stripping out the decimal portion and returning just the integer part.

const myCatWeight = 13.2;
const apxCatWeight = Math.floor(myCatWeight);

const myDogWeight = 22.7;
const apxDogWeight = Math.floor(myDogWeight);

console.log(`My cat weighs about ${apxCatWeight} kilograms.`);  
console.log(`My dog weighs about ${apxDogWeight} kilograms.`);

/* output
My cat weighs about 13 kilograms.  
My dog weighs about 22 kilograms.

For negative numbers, the decimal portion is stripped and 1 is subtracted (because that new number is less than the original number. For example:

const day1Temp = -1.6;
const apxDay1Temp = Math.floor(day1Temp);

const day2Temp = -5.1;
const apxDay2Temp = Math.floor(day2Temp);

console.log(`The temperature for Day 1 was about ${apxDay1Temp}C.`);
console.log(`The temperature for Day 2 was about ${apxDay2Temp}C.`);

/* output
The temperature for Day 1 was about -2C.
The temperature for Day 2 was about -6C.

Notice that in both instances that the number wasn’t ’rounded’. Math.floor() will not round the number for you – it merely strips the decimal portion.

Oddities and Peculiarities

What about numbers that are not ‘numbers’? How will Math.floor() deal with them? Let’s find out!


If the string can be coerced into a number, then Math.floor() will work. Otherwise, it will return a NaN (with one exception – keep reading).


/* output

Objects, undefined, NaN

Each of these will return NaN.

console.log(Math.floor({ myCat: 3 }));

/* output

Booleans, Null, Blank String

It’s not what you think! Like a string, Math.floor() will attempt to coerce the value into a number. Boolean True and False are coerced into 1 and 0, respectively. Null and a Blank String? Those are ‘falsey’ values, and therefore are interpreted as Boolean False – which get coerced into 0.


/* output

While Math.floor() will do exactly what you expect it to do, be careful to make sure you only pass numbers as the argument. Otherwise, you may not get what you expect.

The Video

Here is a video we’ve made on the subject.

Shameless Plug

You can find us everywhere!

Check out all our videos at:

Check out everything at:




Categories: Boring JavaScript Javascript

Tagged as:


Web Tinkerer. No, not like Tinkerbell.

Creator of the game Virtuoid. Boring JavaScript. Visit us at

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: