js的單體內置對象Math

js中的單體內置對象

Global,Math

Math的方法

min(),min()用於確定一組數值中的最大值和最小值。

var max = Math.max(3,54,5,6);
console.log(max);	//max = 54
var value = [1,2,3,4,5,6,7,8,9];
var max = Math.Max.apply(Math,value);

Math.ceil();		//向上舍入
Math.floor();		//向下舍入
Math.round();		//四捨五入
Math.random();		//返回一個大於等於0;小於1的隨機數
console.log( Math.floor(Math.random()*9 +2));//隨機輸出2到10的整數
Math.abs(num); 	//返回絕對值
Math.exp(num);		//返回Math.E的num次冪
Math.log(num);		//num的自然對數
Math.pow(num,power);//num的power次冪
Math.sqrt(num);		//num的平方根


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章