Math 對象和Date對象的常用屬性和方法

Math對象常用方法

Math.PI 圓周率 π的值
Math.random() 生成隨機數
例如:隨機生成5位數的隨機數
function f1(){
var arr=[“0”,“1”,“2”,“3”,“4”,“5”,“6,“7”,“8”,“9”];
var str=”";
for(var i=0;i<5;i++){
var num=parseInt(Math.random()*10);
str+=arr[num];
}
return str;
}
f1();
Math.floor() 向下取整
Math.ceil() 向上取整
Math.round() 取整,四捨五入
Math.abs() 絕對值
Math.max() 最大值
Math.min() 最小值
Math.sin() 正弦
Math.cos() 餘弦
Math.power() 求指數次冪
Math.sqrt() 求平方根

Date對象

getFullYear() 年
getMonth() 月
getDate() 日
getDay() 星期
getHours () 時
getMinutes() 分
getSeconds () 秒
getTime() 毫秒數

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