- Math.ceil() 向上取整数
Math.ceil(1.1) //2
- Math.floor() 想下取整数
Math.floor(1.9) //1
- Math. PI() 取圆周率
Math.PI() //3.1415926....
- Math.round() 四舍五入取整数
Math.round(4.4) //4Math.round(4.5) //5
- Math.abs() 取绝对值
Math.abs(-1) //1Math.abs(1) //1
- Math.pow(x, y)取x的y次方
Math.pow(3, 3) //9Math.poe(2, 3) //8
- Math.sqrt(x)取平方根
Math.sqrt(64) //8Math.sqrt(49) //7
- max(num1, num2, …)取最大值
max(1, 2, 5, 7, 8) //8
- min(num1, num2, …)取最小值
min(1, 5, 4, 6, 8) //1
- Math.random() 取随机数
Math.random() //随机取0~1之间的所有的数不包含0和1Math.random() * 10 //随机取0~10之间的所有的数不包含1和10Math.random() * 10 + 1 //随机取1~11之间的所有的数不包含1和11pareInt(Math.random() * 10) //随机取0~10之间的所有的整数不包含1和10
实例:
var name_list = ['宋飞虎', '仝燕敏', '王锦娅', '赵艳华', '张艳杰', '高春元','杨帅旗', '韩旭', '王培禛', '林汪洋', '王宁', '徐晓辉', '杨潇鹏', '靳松', '王欢','林倩文', '刘志远', '蔡云飞', '侯文康', '姜旭', '杨亚男', '刘兵帅', '刘鹏博','王亚坤', '寇祺', '曹月华', '朱宗茂', '王玉飞', '肖云凡', '高梦杨', '李腾飞','徐正龙', '郝世祺', '王立涛', '岳季成', '刘朗', '李斌', '郑贵宾', '陈万里', '薄乐园']for (var i = 0; i < name_list.length; i++) {var len = Math.floor(Math.random() * (name_list.length));console.log(name_list[len])name_list.splice(len, 1)i--}
- toFixed() 方法可把 Number 四舍五入为指定小数位数的数字。
NumberObject.toFixed(num) // num规定小数点的位数
实例:
alert(num.toFixed(2));
