1、Math.round() “四舍五入”
2、Math.ceil() “向上取整”, 即小数部分直接舍去,并向正数部分进1
3、Math.floor() “向下取整” ,即小数部分直接舍去
alert(Math.ceil(25.9)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.1)); //26
alert(Math.floor(25.9)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.1)); //25
alert(Math.round(25.9)); //26
alert(Math.round(25.5)); //26
alert(Math.round(25.1)); //25
4.random()方法
Math.random()方法返回介于0到1之间一个随机数,不包括0和1
可用于post 请求url 使得浏览器每次都会以为是一个新的请求所以不会读取缓存。
export async function getClassifyList(params) {
return request(`/dict/getClassifyList?${stringify(params)}` + '&rand=' + Math.random());
}
拓展
Math.abs(num)
返回num的绝对值
Math.exp(num)
返回Math.E的num次幂
Math.log(num)
返回num的自然对数
Math.pow(num,power)
返回num的power次幂
Math.sqrt(num)
返回num的平方根
Math.acos(x)
返回x的反余弦值
Math.asin(x)
返回x的反正弦值
Math.atan(x)
返回x的反正切值
Math.atan2(y,x)
返回y/x的反正切值
Math.cos(x)
返回x的余弦值
Math.sin(x)
返回x的正弦值
Math.tan(x)
返回x的正切值