Math常用方法
1、random()
==>语法:Math.random()
==>返回值:0~1之间的随机小数,包0不包1
2、round()
==>语法:Math.round(数字)
==>返回值:四舍五入以后取整数字,只看小数点后一位
3、ceil()
==>语法:Math.ceil(数字)
==>返回值:向上取整后的数字
4、floor()
==>语法:Math.floor(数字)
==>返回值:向下取整后的数字
5、pow()
==>语法:Math.pow(数字,多少次幂)
==>返回值:数字取幂以后的结果
6、sqrt()
==>语法:Math.sqrt(数字)
==>返回值:数字的算术平方根
==>只能是平方根
7、abs()
==>语法:Math.abs(数字)
==>返回值:数字的绝对值
8、max()
==>语法:Math.max(数字1,数字2,数字3,...)
==>返回值:若干个数字中的最大值
==>注意:传递数组不好使
9、min()
==>语法:Math.min(数字1,数字2,数字3,...)
==>返回值:若干个数字中的最小值
==>注意:传递数组不好使
10、PI属性
==>语法:Math.PI
==>得到:近似于数学TT 的值
==>注意:
1、使用不需要()
2、两个字母都要大写
*/
//1、Math.random
/* var res = Math.random();
console.log(res); */
//2、Math.round()
/* var res = Math.round(10.499);
console.log(res); //10 */
//3、Math.ceil()
/* var res = Math.ceil(10.1);
console.log(res); //11
//4、Math.floor(s)
var res = Math.floor(10.1);
console.log(res);//10 */
//5、Math.pow()
/* var res = Math.pow(2, 3);
console.log(res); //8
//6、Math.sqrt()
var res = Math.sqrt(4);
console.log(res);//2 */
//7、Math.abs()
/* var res = Math.abs(-4);
console.log(res); //4
//8、Math.max()
var res = Math.max(1, 2, 3, 4, 5, 6);
console.log(res); //6
//9、Math.min()
var res = Math.min(1, 2, 3, 4, 5, 6);
console.log(res);//1 */
//10、Math.PI
/* var res = Math.PI;
console.log(res);
//3.141592653589793 */