Math函数

来源:互联网 发布:淘宝换货需要先签收吗 编辑:程序博客网 时间:2024/06/05 01:10

1.Math.floor() 向下取整
举例:
Math.floor(18.6)的结果为18
Math.floor(-1.1)的结果为-2
2.Math.round() 四舍五入
举例:
Math.round(18.5)的结果为19
Math.round(-1.1)的结果为-1
Math.round(-1.5)的结果为-1
Math.round(-1.6)的结果为-2
3.Math.ceil() 向上取整
举例:
Math.ceil(-1.1)的结果为-1
Math.ceil(-1.5)的结果为-1
Math.ceil(0.1)的结果为1
4.Math.rint() 返回double值最接近参数的值,如果同样接近则返回偶数值
举例:
Math.rint(-1.1)的结果为-1.0
Math.rint(-1.5)的结果为-2.0
Math.rint(0.5)的结果为0.0

原创粉丝点击