• Math 数学的方法


    Math

        // console.log(Math); // 对象;

        
    Math.max : 获取一组数的最大值

    console.log(Math.max(12, 3, 45, 109, 4));//109

         Math.min

    console.log(Math.min(12, 3, 0, 109, 4));//0

         Math.floor : 向下取整

    console.log(Math.floor(4.999));//4
    console.log(Math.floor(-4.999));//-5

         Math.ceil() : 向上取整

    console.log(Math.ceil(4.01));// 5
    console.log(Math.ceil(-4.01));// -4

        Math.round() : 四舍五入;保留整数;

    console.log(Math.round(4.499));//4

        6.1 Math.random();产生一个[0,1)的随机小数;

    console.log(Math.random());

        6.2 Math.random()产生一个m--n之间的随机整数;

    Math.round(Math.random()*(n-m)+m);
    Math.round(Math.random()*(90-40)+40)

        Math.pow() :取数字的幂次方Math.pow(n,m) n的m次方

    console.log(Math.pow(2, 6));64

        Math.sqrt() :开平方

    console.log(Math.sqrt(64));//8

        Math.abs() :对负数取绝对值;

    console.log(Math.abs(-12));//12

        10 Infinity 无穷大  -Infinity无穷小

        11 更全的方法:来自 W3school

    abs(x) 返回数的绝对值。
    acos(x) 返回数的反余弦值。
    asin(x) 返回数的反正弦值。
    atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。
    atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。
    ceil(x) 对数进行上舍入。
    cos(x) 返回数的余弦。
    exp(x) 返回 e 的指数。
    floor(x) 对数进行下舍入。
    log(x) 返回数的自然对数(底为e)。
    max(x,y) 返回 x 和 y 中的最高值。
    min(x,y) 返回 x 和 y 中的最低值。
    pow(x,y) 返回 x 的 y 次幂。
    random() 返回 0 ~ 1 之间的随机数。
    round(x) 把数四舍五入为最接近的整数。
    sin(x) 返回数的正弦。
    sqrt(x) 返回数的平方根。
    tan(x) 返回角的正切。
    toSource() 返回该对象的源代码。
    valueOf() 返回 Math 对象的原始值。
  • 相关阅读:
    Recyclerview设置间距
    Python-socket / socketserver
    服务器存储空间不足,无法处理此命令
    gitbucket
    一些好用的Linux命令组合
    Python socket模块
    用Python在局域网根据IP地址查找计算机名
    thinkpad开机引导方式变成PCI LAN选项解决
    ipython安装
    python xml
  • 原文地址:https://www.cnblogs.com/MrZhujl/p/9937605.html
Copyright © 2020-2023  润新知