js Math 函数

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的正切值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值