Math:用于执行数学任务,不像 Date 和 String 那样是对象的类,因此没有构造函数 Math()。
方法:
Math.ceil():对小数进行上舍入。
Math.ceil(25.5); //返回26
Math.ceil(-25.5); //返回-25
Math.floor():对小数进行下舍入。
Math.floor(25.5); //返回25
Math.floor(-25.5); //返回-26
Math.round():对小数进行四舍五入(注:在负数的情况下,当小数位是5的时候,不会五入,会舍去)。
Math.round(25.5); //返回26
Math.round(-25.5); //返回-25
Math.random():返回0.0~1.0之间的随机数(包括0,不包括1)。
Math.floor(Math.random() * (max - min+1)) + min; (注:含最大值,含最小值)。
Math.floor(Math.random() * (max - min)) + min; (注:不含最大值,含最小值)。
Math.pow(x,y):返回 x 的 y 次幂。