Javascript Math.ceil()与Math.round()与Math.floor()区别

Math.ceil()向上舍入

1
2
3
alert(Math.ceil(20.1)) //输出 21
alert(Math.ceil(20.5)) //输出 21
alert(Math.ceil(20.9)) //输出 21

 Math.round标准的四舍五入

1
2
3
alert(Math.round(20.1)) //输出 20
alert(Math.round(20.5)) //输出 21
alert(Math.round(20.9)) //输出 21

 Math.floor()向下舍入

1
2
3
alert(Math.floor(20.1)) //输出 20
alert(Math.floor(20.5)) //输出 20
alert(Math.floor(20.9)) //输出 20

转载于:https://my.oschina.net/garyun/blog/602745

猜你喜欢

转载自blog.csdn.net/weixin_33777877/article/details/91774306