js学习总结----Math方法和应用

Math 是数学函数,里面提供了几个操作数字的方法

  1、Math.abs() 取绝对值

  2、Math.ceil() 向上取整

  3、Math.floor() 向下取整

  4、Math.round() 四舍五入  

  5、Math.max(val1,val2,val3) 取最大值

  6、Math.min(val1,val2,val3) 取最小值

  7、Math.random() 获取[0-1)之前的随机小数

    获取[n-m] 之间的随机整数

    Math.round(Math.random()*(m-n)+n)

  获取随机数方法:

 

    

posted @ 2017-06-21 11:15  diasa  阅读(199)  评论(0编辑  收藏  举报