1. 向下取整
parseInt();//直接去除小数部分
Math.floor();
2. 向上取整:
Math.ceil();//向下取整+1
3. 四舍五入
Math.round();
实例:
var number1 = number2 = number3 = number4 = number5 = 2.6;
console.log("5个原始的数据都为",number1);//2.6
console.log('正数部分')
console.log('直接去除小数向下取整',parseInt(number1));//2
console.log('向下取整',Math.floor(number2));//2
console.log('向上取整',Math.ceil(number3));//3
console.log('四舍五入',Math.round(number4));//3
console.log('负数部分')
console.log('直接去除小数向下取整',parseInt(-number1));//-2
console.log('向下取整',Math.floor(-number2));//-3
console.log('向上取整',Math.ceil(-number3));//-2
console.log('四舍五入',Math.round(-number4));//-3