JS 数学对象Math

1.数学对象Math

   //圆周率
        console.log(Math.PI);
        //最大值
        var max = Math.max(9, 6, 3, 7, 999, 45, 21, );
        console.log(max);
        //最小值
        var min = Math.min(9, 6, 3, 7, 999, 45, 21, );
        console.log(min);
        //绝对值
        console.log(Math.abs(-4));
        //求次幂Math.pow(x, y)  
        //参数:求x的y次幂
        console.log(Math.pow(5, 6));
        //向下取整(小数不管多大都只取向下整数)
        //        注意:负值越小越大向下取整时要注意
        console.log(Math.floor(3.14));
        console.log(Math.floor(3.98));
        console.log(Math.floor(-3.14));
        console.log(Math.floor(-3.98));
        //向上取整(小数不管多小都只取向上整数)
        //        注意:负值越小越大向上取整时要注意
        console.log(Math.floor(3.14));
        console.log(Math.floor(3.98));
        console.log(Math.floor(-3.14));
        console.log(Math.floor(-3.98));
        //四舍五入(和数学的中一样)
        console.log(Math.round(3.46));
        console.log(Math.round(3.56));
        //随机数(0-1)之间的小数
        //       toFixed():保留小数点后几位
        console.log(Math.random());
        //练习:取50-100之间的数
        //公式:Math.random()*(max-min+1)+min
        // Math.random() * (100 - 50 + 1) + 50
        console.log(Math.random() * (100 - 50 + 1) + 50);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值