JavaScript Math.floor()

Last Updated On Saturday 2nd Jul 2022

math floor in javascript

The Math.floor() function rounds down a number to the next smallest integer.

Syntax

	Math.floor(x)
	

Parameters

  • x – A number

Returns

Returns the largest integer less than or equal to a given number and returns 0 for null.

floor javascript

	const num = Math.floor(2.8765);
console.log(num);

const num1 = Math.floor(-0.34567);
console.log(num1);

const num2 = Math.floor("44");
console.log(num2);

const num3 = Math.floor(null);
console.log(num3);

const num4 = Math.floor("CodeJagd");
console.log(num4);

const num5 = Math.floor(NaN);
console.log(num5);
	

Output

	2
-1
44
0
NaN
NaN
	

Note: Math.floor() returns for null rather than NaN. Returns NaN also for non Numeric Types

Browser Support

Math.floor() is an ES1 feature. It is fully supported in all browsers.

Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes
javascript floor
floor in javascript
math floor