📅  最后修改于: 2023-12-03 14:42:25.720000             🧑  作者: Mango
Math.floor()
方法返回小于等于传递给它的参数的最大整数。
Math.floor(x)
x
必须:一个数字。Math.floor()
返回的是小于等于传递给函数的参数的最大整数。
console.log(Math.floor(4.9)); // 4
console.log(Math.floor(3.3)); // 3
console.log(Math.floor(2.1)); // 2
console.log(Math.floor(-4.9)); // -5
在第一个示例中,Math.floor(4.9)
返回 4,因为 4 是小于等于 4.9 的最大整数。
在第二个示例中,Math.floor(3.3)
返回 3,因为 3 是小于等于 3.3 的最大整数。
在第三个示例中,Math.floor(2.1)
返回 2,因为 2 是小于等于 2.1 的最大整数。
在第四个示例中,Math.floor(-4.9)
返回 -5,因为 -5 是小于等于 -4.9 的最大整数。
Math.floor()
方法是一个很有用的 JavaScript 方法。它在需要将一个浮点数向下取整到整数时非常有用。它可以格式化数字、计算数学公式,并获取需要处理的数据表。