Math对象中有3个方法用于处理小数值的舍入操作,它们是:Math.ceil()、Math.floor()、Math.round()。

Math.ceil():向上舍入为最接近的整数。

Math.floor():向下舍入为最接近的整数。

Math.round():标准的四舍五入。



alert(Math.ceil(3.2));   // 4
alert(Math.ceil(3.5));   // 4
alert(Math.ceil(3.6));   // 4

alert(Math.floor(3.2));  // 3
alert(Math.floor(3.5));  // 3
alert(Math.floor(3.6));  // 3

alert(Math.round(3.2));  // 3
alert(Math.round(3.5));  // 4
alert(Math.round(3.6));  // 4



 

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: JavaScriptJava