c语言sscanf函数的用法是什么
273
2022-09-21
js Math对象的常用方法
Math 对象
Math 对象用于执行数学任务。属于对象数据类型 typeof Math => ‘object’ Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数,不是某个对象的方法。无需创建它,通过把 Math 作为对象使用就可以调用其所有属性和方法。
Math.abs() 获取绝对值
Math.abs(-12); // 12Math.abs(-0); // 0
Math.ceil() 向上取整Math.floor() 向下取整
Math.ceil(3.14) ; // 4Math.floor(3.14); // 3
Math.round() 四舍五入
Math.round(16.45); // 16Math.round(16.54); // 17
Math.random() 取[0,1)的随机小数
Math.random(); // 0-1 随机小数 Math.random()*10; // 0-10 随机小数
Math.round(Math.random()*10); // 0-10 随机整数
// 获取[n,m]之间的随机整数Math.round(Math.random()*(m-n)+n);Math.round(Math.random()*(9-3)+3); // 3-9 随机整数
Math.max() 获取一组数据中的最大值Max.min() 获取一组数据中的最小值
Math.max(-1,0,1,2,3); // 3Math.max(...[-1,0,1,2,3]); // 3Math.max.apply(null, [-1,0,1,2,3]); // 3Math.min(-1,0,1,2,3); // -1Math.min(...[-1,0,1,2,3]); // -1Math.min.apply(null, [-1,0,1,2,3]); // -1
Math.pow()获取一个值的多少次幂Math.sqrt()对数值开方
Math.pow(3,2); // 9 3的2次方Math.sqrt(9); // 3 9的开方
Math.PI 获取圆周率π 的值
Math.PI; // 3.141592653589793
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~