Learn the basics of math objects in JavaScript with ease

Source: Internet
Author: User
Tags mathematical functions sin

There are also some properties and methods for the built-in math math entries and functions. For example, the Pi property of the Math object will have the property value Pi (3.141 ...), and you can call it like this:

Math.PI

Similarly, standard mathematical functions are the math method. These include trigonometric, logarithmic, exponential, and other functions. Let's say you want to use a trigonometric sin, you can write this:

Math.sin (1.56)

It should be noted that all trigonometric parameters of math are in radians.
Unlike other objects, you cannot create a math object of your own. You can only use the built-in math object.

eg
1.min () and Max (
)

var value = [1,2,3,4,5,6,7,8];
var max = Math.max.apply (Math, values);

2. Rounding Method
Math.ceil (): Rounding up
Math.floor (): Rounding Down
Math.Round (): Rounding

3.random ()
the Math.random () method returns a random number between 0 and 1, excluding 0 and 1

var num = Math.floor (Math.random () *10, + 1)//Returns the number between 1-10

4.round ()
How to use round ().

 
 

5.random ()
How to use random () to return a random number between 1 and 0.

 
 

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.