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() 毫秒數