三个函数都用于浮点数取整。
【Math.round()】:将括号内的数+0.5之后,向下取值。
例1:Math.round(11.4) = (11.4+0.5=11.9) =>11
Math.round(11.6) = (11.6+0.5=12.1) =>12
Math.round(-11.5) = (-11.5+0.5=-11) =>-11
Math.round(-11.4) = (-11.4+0.5=-10.9) =>-11
Math.round(-11.6) = (-11.6+0.5=-11.1) =>-12
【Math.ceil()】:ceil指天花板,取不小于本身的最小整数(向上取整)。
例2:Math.ceil(11.4) = 12
Math.ceil(11.9) = 12
【Math.floor()】:ceil指地板,取不小于本身的最小整数(向下取整)。
例2:Math.ceil(11.4) = 12
Math.ceil(11.9) = 12