JavaScript Intensive Tutorial--javascript Math Object

Source: Internet
Author: User
Tags arithmetic

This article is the official HTML5 training course for Brother Lian it education organization, mainly introduces: JavaScript intensive tutorial--javascript Math (Arithmetic) object

The Math object works by performing common arithmetic tasks.

Round ()
How to use round ().
Random ()
How do I use random () to return a random number between 0 and 1.
Max ()
How to use Max () to return a larger number of two given numbers. (Before ECMASCript v3, the method has only two parameters.) )
Min ()
How to use min () to return a smaller number of two given numbers. (Before ECMASCript v3, the method has only two parameters.) )
Complete reference manual for Math objects
We provide a reference manual for the JavaScript Math object, which includes all the properties and methods available for arithmetic objects.
The manual contains a detailed description of each of the properties and methods and the relevant examples.
Math Object
The Math object works by performing normal arithmetic tasks.
The Math object provides a variety of arithmetic value types and functions. You do not need to define it before using this object.
Syntax for using the properties/methods of math:
var X=math.pi;
var y=math.sqrt (16);
Note: The Math object does not need to be defined before using this object.
Arithmetic value
JavaScript provides 8 arithmetic values that can be accessed by the Math object:
You can refer to the following JavaScript constants using this method:
Math.e
Math.PI
Math.sqrt2
Math.sqrt1_2
Math.ln2
Math.ln10
math.log2e
math.log10e

Arithmetic method
In addition to the arithmetic values that can be accessed by the Math object, there are several functions (methods) that can be used.
The following example rounds a number by using the round method of the Math object.
document.write (Math.Round (4.7));
The above code output is:
5
The following example uses the random () method of the Math object to return an arbitrary number between 0 and 1:
document.write (Math.random ());
The above code output is:
0.4130633108048849
The following example uses the floor () method and random () of the Math object to return a random number between 0 and 11:
document.write (Math.floor (Math.random () *11));
The above code output is:
4

JavaScript Intensive Tutorial--javascript 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.