Home  >  Article  >  Web Front-end  >  Methods of js Math object_basic knowledge

Methods of js Math object_basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:23:491257browse

1. Discard the decimal part and keep the integer part

parseInt(5/2)

2. Round up, if there is a decimal, add 1 to the integer part

Math .ceil(5/2)

3, round down.

Math.round(5/2)

4, round down

Math .floor(5/2)

Math object method

FF: Firefox, IE: Internet Explorer

方法 描述 FF IE
abs(x) 返回数的绝对值。 1 3
acos(x) 返回数的反余弦值。 1 3
asin(x) 返回数的反正弦值。 1 3
atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。 1 3
atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。 1 3
ceil(x) 对数进行上舍入。 1 3
cos(x) 返回数的余弦。 1 3
exp(x) 返回 e 的指数。 1 3
floor(x) 对数进行下舍入。 1 3
log(x) 返回数的自然对数(底为e)。 1 3
max(x,y) 返回 x 和 y 中的最高值。 1 3
min(x,y) 返回 x 和 y 中的最低值。 1 3
pow(x,y) 返回 x 的 y 次幂。 1 3
random() 返回 0 ~ 1 之间的随机数。 1 3
round(x) 把数四舍五入为最接近的整数。 1 3
sin(x) 返回数的正弦。 1 3
sqrt(x) 返回数的平方根。 1 3
tan(x) 返回角的正切。 1 3
toSource() 返回该对象的源代码。 1 -
valueOf() 返回 Math 对象的原始值。 1 4
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn