Properties of the Math object
E: Value E, bottom of the natural logarithm
The natural logarithm of the ln10:10
The natural logarithm of the Ln2:2
LOG2E: logarithm of 2 as the base E
LOG10E: logarithm of 10 as the base E
PI: Value Pie
The square root of the SQRT1_2:1/2
The square root of the Sqrt2:2
Methods for the Math object: maximum and minimum values
Min () &&max () is used to take the minimum and maximum values from a set of numbers.
Example:
Copy Code code as follows:
var Imax=math.max (1,2,3);
alert (IMax);//outputs 3
var imin=math.min (1,2,3);
alert (imin);//outputs 1
Approximately pair value
ABS () is used to return the absolute value of a number.
Example:
Copy Code code as follows:
var inegone=math.abs (-1);
alert (inegone);//oupputs 1
var iposone=math.abs (1);
alert (iposone);//outputs 1
Round decimal to Integer
Ceil () is a rounded up function that always rounds the number up to the nearest value
Floor () is a downward rounding function that always rounds the number down to the nearest value
Round () rounding the rounded method
Example:
Copy Code code as follows:
Alert (Math.ceil (25.5));//oputpus 26
Alert (Math.floor (25.5));//oputpus 25
Alert (Math.Round (25.5));//oputpus 26
Exponential calculation
EXP () used to raise the MATH.E to a specified power
Log () is used to return the natural logarithm of a particular number
POW () is used to raise the specified number to a specified power
sqrt () is used to return the square root of the specified number
Trigonometric methods
ACOs (x) is used to return the inverse cosine value of x
ASIN (x) is used to return the inverse chord value of x
Atan (x) is used to return the tangent value of X
ATAN2 (y,x) is used to return the y/x's inverse cosine value
COS (x) is used to return the cosine value of X
Sin (x) is used to return the sine value of x
Tan (x) is used to return the tangent value of X
Random number function
Random () is used to return a random number between 0 and 1, excluding 0 and 1.
Select a random number within a range:
Copy Code code as follows:
function Selectfrom (ifirstvalue,ilastvalue) {
var ichoices=ilastvalue-ifirstvalue+1;
Return Math.floor (Math.random () *ichoices+ifirstvalue);
}
Demo
var inum=selectfrom (2,10);
Author: artwl
Source: http://artwl.cnblogs.com