zoukankan      html  css  js  c++  java
  • js Math对象方法 (个人学习笔记)

    方法:

    1.丢弃小数部分,保留整数部分
            parseInt(5/2)

    2.向上取整,有小数就整数部分加1

            Math.ceil(5/2)

    3,四舍五入.

            Math.round(5/2)

    4,向下取整

            Math.floor(5/2)

    5,返回数的绝对值

            Math.abs(x)

    6,返回 x 和 y 中的最高值

            Math.max(x,y) 

    7,返回 x 和 y 中的最低值

            Math.min(x,y)

    8,返回 0 ~ 1 之间的随机数

            Math.random()

    9, 返回数的反余弦值

            Math.acos(x)

    10,返回数的反正弦值

            Math.asin(x) 

    11, 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值

            Math.atan(x)

    12,返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)

            Math.atan2(y,x)

    13,返回数的余弦

            Math.cos(x)

    14,返回 e 的指数

            Math.exp(x) 

    15,返回数的自然对数(底为e)

            Math.log(x)

    16,返回 x 的 y 次幂

            Math.pow(x,y) 

    17,返回数的正弦

            Math.sin(x) 

    18,返回一个角的正切

            Math.tan(x) 

    19,返回数的平方根

            Math.sqrt(x) 

    20,代表对象的源代码

            Math.toSource() 

    21,返回一个 Math 对象的原始值

            Math.valueOf() 

    22.js中如何快速获取数组中的最大值最小值
           var a=[1,2,3,5];
          alert(Math.max.apply(null, a));//最大值
          alert(Math.min.apply(null, a));//最小值
    多维数组可以这么修改:
          var a=[1,2,3,[5,6],[1,4,8]];
          var ta=a.join(",").split(",");//转化为一维数组
          alert(Math.max.apply(null,ta));//最大值
          alert(Math.min.apply(null,ta));//最小值

  • 相关阅读:
    SAP S/4HANA extensibility扩展原理介绍
    SAP CRM系统订单模型的设计与实现
    使用nodejs代码在SAP C4C里创建Individual customer
    SAP Cloud for Customer Account和individual customer的区别
    Let the Balloon Rise map一个数组
    How Many Tables 简单并查集
    Heap Operations 优先队列
    Arpa’s obvious problem and Mehrdad’s terrible solution 思维
    Passing the Message 单调栈两次
    The Suspects 并查集
  • 原文地址:https://www.cnblogs.com/web-chuan/p/9110418.html
Copyright © 2011-2022 走看看