Math對象 里面提供的方法,可以幫助我們解決算術(shù)問題
提供的方法:
(1)? Math.random()?
作用:返回一個0到1之間的隨機(jī)數(shù)
語法;? console.log(parseInt(Math.random()*1001)+1000);
(2)abs()?
作用:返回一個數(shù)的絕對值
語法:console.log(Math.abs(-55));
(3)ceil()?
作用:向上取整(只要有小數(shù)叛氨,就進(jìn)一)
語法:console.log(Math.ceil(55.01));
(4)floor()?
作用:向下取整(去掉所有小數(shù)點)
語法:console.log(Math.floor(55.99));
(5)max()?
作用:返回最大值
語法:?console.log(Math.max(11,22,33,38,2,3,4));
(6)min()
作用: 返回最小值
語法:?console.log(Math.min(11,22,33,38,2,3,4));
(7)pow()?
作用:返回指定數(shù)的次冪
語法:console.log(Math.pow(3,3));
? ? ? ? ? ?console.log(Math.pow(4,4));
(8)round()?
作用:四舍五入
語法:?console.log(Math.round(55.5));
? ? ? ? ? ? console.log(Math.round(55.4));
? ? ? ? ? ? console.log(Math.round(-55.5));
? ? ? ? ? ? console.log(Math.round(-55.6));
(9)sqrt()?
作用:開平方根
語法:? ? ? ? ? console.log(Math.sqrt(16))? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??