Home > Web Front-end > JS Tutorial > Overview of using Math object methods in JavaScript_Basic knowledge

Overview of using Math object methods in JavaScript_Basic knowledge

WBOY
Release: 2016-05-16 17:05:52
Original
1301 people have browsed it

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, rounded up.

Math.round(5/2)

4, round down

Math.floor(5/2)

Methods of Math object
FF: Firefox, N: Netscape, IE: Internet Explorer

Method description FF N IE
abs(x) Returns the absolute value of the number 1 2 3
acos(x) Returns the inverse cosine of the number 1 2 3
asin(x) Returns the inverse of the number Chord value 1 2 3
atan(x) Returns the arctangent of x as a value between -PI/2 and PI/2 radians 1 2 3
atan2(y,x) Returns the value from x Angle from axis to point (x,y) (between -PI/2 and PI/2 radians) 1 2 3
ceil(x) Rounds up a number. 1 2 3
cos(x) Returns the cosine of a number 1 2 3
exp(x) Returns the exponent of e. 1 2 3
floor(x) rounds a number down. 1 2 3
log(x) Returns the natural logarithm of the number (base e) 1 2 3
max(x,y) Returns the highest value between x and y 1 2 3
min(x ,y) Returns the lowest value between x and y 1 2 3
pow(x,y) Returns x raised to the y power 1 2 3
random() Returns a random number between 0 ~ 1 1 2 3
round(x) Rounds a number to the nearest integer 1 2 3
sin(x) Returns the sine of the number 1 2 3
sqrt(x) Returns the square root of the number 1 2 3
tan(x) returns the tangent of an angle 1 2 3
toSource() represents the source code of the object 1 4 -
valueOf() returns the original value of a Math object

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template