var arg1 = 12.2;
var arg2 = 12.5;
var arg3 = 12.7;
< strong > ceil():将小数部分一律向整数部分进位</ strong >
var c1 = Math.ceil(arg1);
var c2 = Math.ceil(arg2);
var c3 = Math.ceil(arg3);
console.log(c1,c2,c3) // 13 13 13
< strong > floor():一律舍去,仅保留整数。</ strong >
var f1 = Math.floor(arg1);
var f2 = Math.floor(arg2);
var f3 = Math.floor(arg3);
console.log(f1,f2,f3) // 12 12 12
< strong > round():进行四舍五入</ strong >
var r1 = Math.round(arg1);
var r2 = Math.round(arg2);
var r3 = Math.round(arg3);
console.log(r1,r2,r3) //12 13 13
|