1. You cannot explicitly create a math object and use it directly;
2.Math objects cannot store data, unlike String,date objects;
3. Before you know the parseint () function will make a decimal integer (so 24.999 becomes 24) by eliminating everything after the decimal point. Often we need more accurate calculations.
So through the math object's several methods:
Round (): When the decimal is 0.5 or greater than 0.5, upward into a bit;
Ceil (): Always round up so that 23.75 becomes 24,23.25;
Floor (): Always round down, so 23.75 becomes 23,23.25;
<doctype html>
var dicethrow=math.round (Math.random () *6) +1;
document.write ("You threw a" +dicethrow);
Attach the method of the Math object
1. Discard the fractional part and keep the whole number of parts
parseint (5/2)
2. Take up the whole, there are decimal numbers on the whole part plus 1
Math.ceil (5/2)
3, rounded.
Math.Round (5/2)
4, take the whole down.
Math.floor (5/2)
Methods of the Math object
Ff:firefox, N:netscape, Ie:internet Explorer
method to describe FF N IE
ABS (x) returns the absolute value of the number 1 2 3
ACOs (x) returns the inverse cosine value of the number 1 2 3
ASIN (x) returns the inverse string value of the number 1 2 3
Atan (x) returns the tangent value of X to 1 2 3, with a value between-PI/2 and PI/2 radians
ATAN2 (y,x) returns the angle (between-PI/2 and PI/2 radians) from the X axis to point (x,y) 1 2 3
Ceil (x) rounds a number. 1 2 3
COS (x) returns the cosine of the number 1 2 3
EXP (x) returns the exponent of E. 1 2 3
Floor (x) rounds a number down. 1 2 3
Log (x) returns the natural logarithm of the number (bottom e) 1 2 3
Max (X,y) returns the highest value in X and y 1 2 3
MIN (x,y) returns the lowest value in X and y 1 2 3
POW (x,y) returns the y power of x 1 2 3
Random () returns a random number between 0 ~ 1 1 2 3
Round (x) rounding 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 a corner 1 2 3
Tosource () represents the object's source code 1 4-
ValueOf () returns the original value of a Math object
1 math.abs (num): Returns the absolute value of num
2 Math.acos (num): Returns the inverse cosine value of num
3 Math.asin (num): Returns the inverse chord value of num
4 Math.atan (num): Returns the tangent value of num
5. Math.atan2 (Y,X): Returns the tangent value of the quotient of y divided by X
6 Math.ceil (num): Returns the smallest integer greater than num
7 Math.Cos (num): Returns the cosine of num
8. Math.exp (x): Returns the number of X powers at the base of natural numbers
9 Math.floor (num): Returns the largest integer less than num
10.math.log (num): Returns the natural logarithm of num
11.math.max (NUM1,NUM2): Returns the larger of NUM1 and num2
12.math.min (NUM1,NUM2): Returns the smaller of NUM1 and num2
13.math.pow (X,y): Returns the value of the Y-second side of X
14.math.random (): Returns a random number from 0 to 1
15.math.round (num): Returns the value of Num rounding
16.math.sin (num): Returns the sine value of num
17.MATH.SQRT (num): Returns the square root of num
18.math.tan (num): Returns the tangent value of num
19.MATH.E: Natural Numbers (2.718281828459045)
Natural logarithm of the 20.math.ln2:2 (0.6931471805599453)
Natural logarithm of the 21.math.ln10:10 (2.302585092994046)
Natural number of 22.math.log2e:log 2 (1.4426950408889634)
Natural number of 23.math.log10e:log 10 (0.4342944819032518)
24.math.pi: π (3.141592653589793)
Square roots of 25.MATH.SQRT1_2:1/2 (0.7071067811865476)
Square roots of 26.math.sqrt2:2 (1.4142135623730951)
The above mentioned is the entire content of this article, I hope you can enjoy.