Math對象的方法有:abs()、acos()、asin()、atan()、cos()、floor()、log()、max()、min()、pow()、random()、round()、sin()、sqrt()、tan()、exp()等等。
本教程操作環(huán)境:windows7系統(tǒng)、ECMAScript 5版、Dell G3電腦。
Math 對象用于執(zhí)行數(shù)學(xué)任務(wù)。
Math對象的方法
-
abs(x):返回數(shù)的絕對值。
-
acos(x):返回數(shù)的反余弦值。
-
asin(x):返回數(shù)的反正弦值。
-
atan(x):以介于 -PI/2 與 PI/2 弧度之間的數(shù)值來返回 x 的反正切值。
-
atan2(y,x):返回從 x 軸到點 (x,y) 的角度(介于 -PI/2 與 PI/2 弧度之間)。
-
ceil(x):對數(shù)進行上舍入。
-
cos(x):返回數(shù)的余弦。
-
exp(x):返回 e 的指數(shù)。
-
floor(x):對數(shù)進行下舍入。
-
log(x):返回數(shù)的自然對數(shù)(底為e)。
-
max(x,y):返回 x 和 y 中的最高值。
-
min(x,y):返回 x 和 y 中的最低值。
-
pow(x,y):返回 x 的 y 次冪。
-
random():返回 0 ~ 1 之間的隨機數(shù)。
-
round(x):把數(shù)四舍五入為最接近的整數(shù)。
-
sin(x):返回數(shù)的正弦。
-
sqrt(x):返回數(shù)的平方根。
-
tan(x):返回角的正切。
-
toSource():返回該對象的源代碼。
-
valueOf():返回 Math 對象的原始值。
【推薦學(xué)習(xí):javascript高級教程】