Math.round(11.5)等于多少?Math.round(-11.5)等于多少?

来源:互联网 发布:阿里云 公网流量费用 编辑:程序博客网 时间:2024/04/27 18:15

Math类提供的几个常用的方法就是  Math.ceil(x);  Math.floor(x); Math.round(X);Math.random();等等。

  ceil 顾名思义,天花板,就是向上取整咯。

 floor 地板  就是向下取整了

  最后  Math.round(x)这个有点小小的繁琐:  Math.round(x)=Math.floor(x+0.5);


所以 Math.round(11.5)等于12

Math.round(-11.5)等于11

0 0
原创粉丝点击