JS中常用Math对象常用方法的整理

来源:互联网 发布:网络教育统考查询 编辑:程序博客网 时间:2024/05/21 00:15

Math.floor():向下取整(下舍去)
Math.ceil():向上取整(上进入)
Math.round():四舍五入
Math.abs():取绝对值
Math.cos():余弦值
Math.sin():正弦值
Math.max():比较(取大)
Math.min():比较(取小)
Math.pow() : 取幂(两个参数第一个参数为底数,第二个为指数)
Math.sqrt() : 开平方
Math.random:0~1的一个随机数

对常用随机数方法的扩展:
1、Math.round(Math.random())//0,1随机
2、Math.round(Math.random()*a) //0~a随机
3、Math.round(Math.random()*(a-b)+b)//b~a随机