JavaScript Math

来源:互联网 发布:matcher java 编辑:程序博客网 时间:2024/04/27 07:17
Math内置对象的常见API(http://www.w3school.com.cn/jsref/jsref_obj_math.asp)
Math.random()   取值范围[0~1) 
Math.round()    四舍五入   Math.round(-11.5) //-11 (向上取整)
Math.max()      求最大值
Math.min()      求最小值
Math.abs()      求绝对值
Math.sqrt()     求开平方
Math.pow(x,y)   x的y次方  Math.pow(27,1/3) //3 开三次方
Math.floor()    向下取整
Math.ceil()     向上取整

三角函数
Math.sin()
Math.cos()
Math.tan()
尝试使用DIV画出 正弦曲线



//随机生成一个min-max之间的数字(包含min和max)function randomInt(min, max) {return Math.round(Math.random() * (max - min)) + min;}





原创粉丝点击