zoukankan      html  css  js  c++  java
  • HTML DOM教程 48JavaScript Math 对象

    HTML DOM教程 48-JavaScript Math 对象

      Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数,不是某个对象的方法。

      1:Math 对象的方法

    方法 描述 FF N IE
    abs(x) 返回数的绝对值 1 2 3
    acos(x) 返回数的反余弦值 1 2 3
    asin(x) 返回数的反正弦值 1 2 3
    atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值 1 2 3
    atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间) 1 2 3
    ceil(x) 对一个数进行上舍入。 1 2 3
    cos(x) 返回数的余弦 1 2 3
    exp(x) 返回 e 的指数。 1 2 3
    floor(x) 对一个数进行下舍入。 1 2 3
    log(x) 返回数的自然对数(底为e) 1 2 3
    max(x,y) 返回 x 和 y 中的最高值 1 2 3
    min(x,y) 返回 x 和 y 中的最低值 1 2 3
    pow(x,y) 返回 x 的 y 次幂 1 2 3
    random() 返回 0 ~ 1 之间的随机数 1 2 3
    round(x) 把一个数四舍五入为最接近的整数 1 2 3
    sin(x) 返回数的正弦 1 2 3
    sqrt(x) 返回数的平方根 1 2 3
    tan(x) 返回一个角的正切 1 2 3
    toSource() 代表对象的源代码 1 4 -
    valueOf() 返回一个 Math 对象的原始值 1 2 4

      2:Math 对象的属性

    属性 描述 FF N IE
    constructor 对创建此对象的函数的引用 1 2 4
    E 常量 e,自然对数的底数 (约等于2.718) 1 2 3
    LN2 返回 2 的自然对数(约等于0.693) 1 2 3
    LN10 返回 10 的自然对数(约等于2.302) 1 2 3
    LOG2E 返回以 2 为底的 e 的对数 (约等于 1.414) 1 2 3
    LOG10E 返回以 10 为底的 e 的对数 (约等于0.434) 1 2 3
    PI 返回圆周率 (约等于3.14159) 1 2 3
    prototype 允许您向对象添加属性和方法 1 2 4
    SQRT1_2 返回 2 的平方根除 1 (约等于 0.707) 1 2 3
    SQRT2 返回 2 的平方根 (约等于 1.414) 1 2 3

      3:abs() 方法

    在本例中,我将取得正数和负数的绝对值:

    <script type="text/javascript">

    document.write(Math.abs(7.25) + "<br />")
    document.write(Math.abs(-7.25) + "<br />")
    document.write(Math.abs(7.25-10))

    </script>

    输出:

    7.25
    7.25

    4:floor() 方法  

    floor() 方法执行的是向下取整计算,它返回的是小于或等于函数参数,并且与之最接近的整数:

    <script type="text/javascript">

    document.write(Math.floor(0.60) + "<br />")
    document.write(Math.floor(0.40) + "<br />")
    document.write(Math.floor(5) + "<br />")
    document.write(Math.floor(5.1) + "<br />")
    document.write(Math.floor(-5.1) + "<br />")
    document.write(Math.floor(-5.9))

    </script>

    输出:

    0
    0
    5
    5
    -6
    -6

    5:random() 方法

    在本例中,我们将取得介于 0 到 1 之间的一个随机数:

    <script type="text/javascript">

    document.write(Math.random())

    </script>

    输出:

    0.16184044615443094

  • 相关阅读:
    python,可变参数
    python process,queue
    python 进程池Pool
    python 中的set与list,tuple
    python 元组tuple
    深夜装ubuntu
    python中的协程
    python Queue在两个地方
    (转载)Spring mvc中@RequestMapping 6个基本用法小结
    数据库jdbc连接--【DRP】
  • 原文地址:https://www.cnblogs.com/pricks/p/1451086.html
Copyright © 2011-2022 走看看