JS学习(6)----Math And Random
来源:互联网 发布:硅谷ios程序员 编辑:程序博客网 时间:2024/05/16 07:22
1.Math
一些常用的数学方法,包括随机数,绝对值等等。
(1)Math.PI
PI = 3.141592653589793
(2)Math.round(num)
四舍五入取整数
Math.round(1.2); 1Math.round(1.5); 2
(3)Math.pow(n, e)
第一个参数是基数,第二个参数是指数
Math.pow(2,3); // 8
(4)Math.sqrt(num)
开平方根
Math.sqrt(36); // 6
(5)Math.abs(num)
取绝对值
Math.abs(-1.2); // 1.2
(6)Math.ceil(num) 和 Math.floor(num)
一个是向上取整,一个是向下取整
Math.ceil(1.2); // 2Math.floor(1.2); // 1
(7)Math.sin()和Math.cos();
Math.sin(90 * Math.PI / 180); // 1Math.cos(0 * Math.PI / 180); // 1
(8)Math.min(arr)和Math.max(arr)
Math.min(0, 2, 4, 1); // 0Math.max(0, 2, 4, 1); // 4
(9)Math.random()
返回的是0-1之间的小数
Math.random();
2.随机数
Math.floor(Math.random()*10); // 0-9之间的随机数Math.floor(Math.random()*11); // 0-10之间的随机数Math.floor(Math.random()*10 + 1); // 1-10之间的随机数
function getRndInteger(min, max) { return Math.floor(Math.random() * (max - min) ) + min;} // [min,max)
function getRndInteger(min, max) { return Math.floor(Math.random() * (max - min + 1) ) + min;} // [min,max]
阅读全文
0 0
- JS学习(6)----Math And Random
- js Math.random()
- 学习Math、Random类
- JS中parseInt()、random()及Math.cell()函数的学习
- js中parseInt();random();Math.ceil的学习
- JS:Math.random(),Math.ceil(),Math.floor()与Math.round()
- JS获取随机数 Math.random()
- [JS]Math.random()随机数的二三事
- [转][JS]Math.random()随机数的二三事
- js Math.random() 随机数 1-10之间
- Math.random()
- Math.random()
- Math.random()
- math.random()
- math.random()
- Math.random()
- math.random()
- math.random()
- python zip() 函数使用
- 视觉SLAM综述(上)
- 小型抓图爬虫程序实现c++
- solr清除所有索引
- 235. Lowest Common Ancestor of a Binary Search Tree
- JS学习(6)----Math And Random
- MySQL 数据类型
- Orika简单使用
- Jsp页面通过href拼接url向后台传中文乱码问题
- 成为更好开发者的几点建议
- 华科14_2
- JSTL
- 不同编译器对于(a++)*(a++)和(a++)*(++a)和(++a)*(a++)和(++a)*(++a)的运算结果
- [牛客网]错题整理(2)