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