Usage of Math object methods in JavaScript

Source: Internet
Author: User
Tags natural logarithm rounds

1. Discard the fractional part and retain the integer part.
ParseInt (5/2)

2. rounded up. If there is a decimal number, add 1 to the integer part.

Math. ceil (5/2)

3. rounding.

Math. round (5/2)

4. Round down

Math. floor (5/2)

Math object Method
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 numbers 1 2 3
Asin (x) returns the inverse sine value of the number 1 2 3
Atan (x) returns the arc tangent of x with a value between-PI/2 and PI/2 radian. The value is 1 2 3.
Atan2 (y, x) returns the angle (between-PI/2 and PI/2 radian) from the x-axis to the point (x, y). 1 2 3
Ceil (x) rounds up a number. 1 2 3
Cos (x) returns the cosine of the number 1 2 3
Exp (x) returns the e index. 1 2 3
Floor (x) is used to remove a number. 1 2 3
Log (x) returns the natural logarithm of the number (Base e) 1 2 3
Max (x, y) returns the highest value of 1 2 3 in x and y.
Min (x, y) returns the minimum value of 1 2 3 in x and y.
Pow (x, y) returns x's y power 1 2 3
Random () returns 0 ~ Random number between 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 () indicates the source code of the object 1 4-
ValueOf () returns the original value of a Math object.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.