Math.round和floor

来源:互联网 发布:怎么找网络推手 编辑:程序博客网 时间:2024/06/05 21:00

输出例子如下:

Math.round(-1.4)=-1

Math.round(-1.5)=-1
Math.round(-1.6)=-2

Math.round(1.4)=1
Math.round(1.5)=2
Math.round(1.6)=2

Math.floor(-1.6)=-2.0
Math.floor(-1.5)=-2.0
Math.floor(-1.4)=-2.0

Math.floor(1.6)=1.0
Math.floor(1.5)=1.0

Math.floor(1.4)=1.0


总结:1.round相当于四舍五入 ,但负数-1.5“四舍五入”后等于-1;

    2.floor对于相当于返回比x(参数)小的 最大的整数。

原创粉丝点击