JS Math方法

 /*
     1. Math.round()
       正数四舍五入:1 2 3 4 舍
                     5 6 7 8 9 进
                     -1 > -2
       负数四舍五入:6 7 8 9 进 值变小
                     1 2 3 4 5 舍 值变大

     */
        console.log(Math.round(5.4));
        console.log(Math.round(5.5));
        console.log(Math.round(-5.6));
        console.log(Math.round(-5.7));
        console.log(Math.round(-5.8));
        console.log(Math.round(-5.9));
        console.log('--->',Math.round(-5.5));
        console.log(Math.round(-5.2));
        console.log(Math.round(-5.1));
        console.log(Math.round(-5.3));
        console.log(Math.round(-5.4));

    /*
    2.Math.floor()
       向下取整:舍去小数部分
     */
        console.log(Math.floor(5.9));
        console.log(Math.floor(5.1));
        console.log(Math.floor(-5.1));//-6
    /*
    3.Math.ceil();
    向上取整
     */
        console.log('ceil',Math.ceil(5.01));
        console.log('ceil',Math.ceil(5.9));
        console.log('ceil',Math.ceil(-5.9));
    /*
     4.Math.abs();
     绝对值
     */

        console.log('abs',Math.abs(-2));
        console.log(Math.abs(2));

    /*
     5.Math.max()、Math.min();
     最大值 最小值
     */

        console.log('max',Math.max(10,20,-9,100));
        console.log('min',Math.min(10,20,-9,100));
        //Math.pow(n,m): 求 n的m次方  n^m
        console.log('pow',Math.pow(2,4));
        console.log('sqrt',Math.sqrt(64));

    /*
     6.三角函数:
       角度转为弧度公式: π/180*角度
        参数为弧度:使用时要把角度转为弧度
     */
        var result = Math.sin(Math.PI/180*30);
        console.log(result);
        result = Math.tan(Math.PI/180*45);
        console.log(result);

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值