JavaScript Math.floor() 函数

Math.floor(x) -- 返回小于等于数字参数的最大整数,对数字进行下舍入

floor函数语法

Math.floor(x);

floor函数参数

   x -- 为number类型的数字

floor函数返回值

返回小于等于x的最大整数
floor函数示例

document.write(Math.floor(5.99));
document.write(Math.floor(-5.99));
document.write(Math.floor(1.01));
document.write(Math.floor(-1.01));

结果:
5
-6
1
-2