小数值舍入为整数的几个方法:
1.Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;
2.Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;
3.Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数;
1
2
3
4
5
6
7
8
9
|
alert(Math.ceil(25.9));
//26
alert(Math.ceil(25.5));
//26
alert(Math.ceil(25.1));
//26
alert(Math.round(25.9));
//26
alert(Math.round(25.5));
//26
alert(Math.round(25.1));
//25
alert(Math.floor(25.9));
//25
alert(Math.floor(25.5));
//25
alert(Math.floor(25.1));
//25
|