Math的几个常用的函数
Math.ceil() //向上取值
Math.floor() // 向下取值
Math.round() // 四舍五入
Math.abs() //取绝对值
Math.random() //随机数
Math.ceil() //向上取值
//举个例子
document.write(Math.ceil(0.7)) //1
document.write(Math.ceil(0.2)) //1
document.write(Math.ceil(6)) //6
document.write(Math.ceil(2.3)) //3
document.write(Math.ceil(-2.2)) //-2
document.write(Math.ceil(-3.9)) //-3
Math.floor() // 向下取值
//举个例子
document.write(Math.floor(0.60)) //0
document.write(Math.floor(0.40)) //0
document.write(Math.floor(5)) //5
document.write(Math.floor(5.1)) //5
document.write(Math.floor(-5.1)) //-6
document.write(Math.floor(-5.9)) //-6
Math.round() // 四舍五入
//举个例子
document.write(Math.round(0.60)) //1
document.write(Math.round(0.50)) //1
document.write(Math.round(0.49)) //0
document.write(Math.round(-4.40)) //-4
document.write(Math.round(-4.60)) //-5
Math.abs() //取绝对值
document.write(Math.abs(-10)) //10
document.write(Math.abs(null)) //0
document.write(Math.abs(20)) //20
document.write(Math.abs('en')) //NaN
Math.random() //随机数,大于0小于1的随机数不包含1
Math.random()*10 //[0,10) 0--10的随机数不包括10