Math对象的方法

1.min()和max()方法用于确定一组值中的最小值和最大值。

例如 var max = Math.max(45,69,2);//max=69

       var min = Math.min(45,69,2);//min =2

2.舍入方法(小数值舍入返回整数)

    Math.ceil():向上舍入

    Math.floor():向下舍入

    Math.round():四舍五入

3.random()方法

   Math.random()方法返回介于0和1之间的一个随机数,不包括0和1。利用此方法可以从某个整数范围内随机选择一个值:值=Math.floor(Math.random() * 可能值的总数 + 第一个可能的值)。 可以用来取数组中的某项值

  如:2~9中的某个值=Math.floor(Math.random() * 8 + 2)

posted @ 2012-12-11 17:38  lanse_yan  阅读(186)  评论(0编辑  收藏  举报