取整
//上取整
Math.ceil(num);
//下取整
Math.floor(num);
//四舍五入 取整
Math.round(num);
//自定义 取整
function round(num, 位数) {
num *= Math.pow(10,位数);
num = Math.round(num);
return num / Math.pow(10,位数);
}
乘方&&开平方
//乘方
Math.pow(10,2); //10的2次方
//开平方
Math.sqrt(9); //返回平方根 3
最大/小值
//最大值
Math.max(1,3,5,2); //5
//最小值
Math.min(1,3,5,2); //1
随机数
0到1之间
//0到1之间
Math.random(); //0到1之间的小数
//最小值到最大值之间随机整数
parseInt(Math.random()*(max-min+1)+min);