js/Math

1、Math.abs( )

  作用该方法返回参数值得绝对值

    Math.abs( 1 )  // 1

    Math.abs( -1 )  // 1

2、Math.max( )

  作用:该方法返回参数之中最大的那个值

    Math.max(2, -1, 5)  // 5

3、Math.min( )

  作用:该方法返回参数之中最大小的那个值

    Math.min(2, -1, 5)  // -1

4、Math.floor( )

  作用:该方法返回小于参数值的最大整数

    Math.floor(3.2)  // 3

    Math.floor(-3.2)  // -4

5、Math.ceil( )

  作用:该方法返回大于参数值的最小整数

    Math.ceil(3.2)  // 4

    Math.ceil(-3.2)  // -3

6、Math.round( )

  作用:该方法用于四舍五入

    Math.round( 0.1 )  // 0

    Math.round( 0.5 )  // 1

    Math.round( 0.6 )  // 1

    Math.round( -1.1 )  // -1

    Math.round( -1.5 )  // -1

    Math.round( -1.6 )  // -2

7、Math.pow( )

  作用:该方法返回以第一个参数为底数,第二个参数为幂的指数值

    Math.pow( 2, 3 )  // 8

8、Math.sqrt( )

  作用:该方法返回参数值的平方根,如果参数是一个负值,则返回NaN

    Math.sqrt( 4 )  // 2

    Math.sqrt( -4 )  // NaN

9、Math.random( )

  作用:该方法返回0到1之间的一个随机数,可能等于0,但是一定小于1

    Math.random( )  // 0.7136987526655

    Math.random( )  // 0.1235441525454 

猜你喜欢

转载自www.cnblogs.com/cuishuangshuang/p/12641005.html