JavaScript 的 Math.floor() 函数

Math.floor() 返回小于或等于一个给定数字的最大整数。

可以理解 Math.floor()为向下取整。

与其相对的是 Math.ceil() ,这个是向上取整。

如下面的代码:

Math.floor( 45.95);
// 45
Math.floor( 45.05);
// 45
Math.floor( 4 );
// 4
Math.floor(-45.05);
// -46
Math.floor(-45.95);
// -46

unnamed

上图演示了这个函数的一些小对比。

https://www.ossez.com/t/javascript-math-floor/13731

原文地址:https://www.cnblogs.com/huyuchengus/p/15256648.html