JavaScript基礎知識(Math的方法)
阿新 • • 發佈:2018-08-09
ava pow con 1.2 向上 次方 dom var script
Math的方法
Math : 對象數據類型 ;
Math: {} 是window下的一個鍵值對; 屬性名叫Math,屬性值是一個對象
var obj = {a:1}; console.log(obj.a); console.log(window.Math);
1. Math.abs() : 取絕對值;
Math.abs(-1.2)
2. Math.floor() : 向下取整
3.Math.ceil() : 向上取整
4.Math.max() : 取最大值
Math.max(12,7,89,100,56,3)
5.Math.min() : 取一組數的最小值
6.Math.random() 取隨機數,取值範圍[0,1)
7.Math.round() : 四舍五入取整
取60-90的隨機整數 Math.round(Math.random()*(90-60)+60)
8.取m-n之間的隨機整數
Math.round(Math.random()*(n-m)+m)
9.Math.pow : 取冪次方
Math.pow(2,3)
10.Math.sqrt() : 開平方;
Math.sqrt(25)
JavaScript基礎知識(Math的方法)