Js-math Object
A. Math Object
Math object, which is a mathematical object that provides a mathematical calculation of the data
Note: The Math object is an intrinsic object, and you can call all of its properties and methods without creating it, directly using math as an object. This is the difference between it and the Date,string object.
Second, Math object properties
Properties |
Description |
E |
Returns the arithmetic constant E, which is the base of the natural logarithm (approximately equal to 2.718281828459045). |
LN2 |
Returns the natural logarithm of 2 (approximately equal to 0.693). |
LN10 |
Returns the natural logarithm of 10 (approximately equal to 2.302). |
Log2e |
Returns the logarithm of E with a base of 2 (approximately equal to 1.414). |
log10e |
Returns the logarithm of E with a base of 10 (approximately equal to 0.434). |
Pi |
Returns the Pi (approximately equal to 3.141592653589793). |
Sqrt1_2 |
Returns the reciprocal of the square root that returns 2 (approximately equals 0.707). |
SQRT2 |
Returns the square root of 2 (approximately equal to 1.414). |
Third, the Math object method
Method |
Description |
ABS (x) |
The absolute value of the return number. |
ACOs (x) |
The inverse cosine value of the returned number. |
ASIN (x) |
Returns the inverse chord value of the number. |
Atan (x) |
Returns the inverse tangent of x with a value between-PI/2 and PI/2 radians. |
ATAN2 (y,x) |
Returns the angle from the x-axis to the point (X, y) (between-PI/2 and PI/2 radians). |
Ceil (x) |
The logarithm is rounded up. |
COS (x) |
The cosine of the returned number. |
EXP (x) |
Returns the exponent of E. |
Floor (x) |
The logarithm is rounded down. |
Log (x) |
Returns the natural logarithm of the number (bottom is e). |
Max (x, y) |
Returns the highest value in X and Y. |
Min (x, y) |
Returns the lowest value in X and Y. |
Pow (x, y) |
Returns the Y power of X. |
Random () |
Returns a random number between 0 and 1. |
Round (x) |
Rounds the number to the nearest integer. |
Sin (x) |
Returns the sine of a number. |
sqrt (x) |
Returns the square root of the number. |
Tan (x) |
Returns the tangent of a corner. |
Tosource () |
Returns the source code for the object. |
ValueOf () |
Returns the original value of the Math object. |
Iv. examples
1, Math.Abs (value): Return absolute value
Math.Abs (' 123 '); = 123: Pure numeric string Math.Abs ('-123 '); = 123math.abs (123); = 123math.abs (-123); = = 123math.abs (' 123a '); = = NaN: Non-pure numeric string
Note: parameter: value {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {number} returns the absolute value of the parameter. If the argument is not a number, the Nan is returned.
2, Math.ceil (value): Rounding a number up, not rounding
Math.ceil (2.7); = 3math.ceil (2.3); = 3:2.3 rounding Up returns 3math.ceil (-2.7); = -2math.ceil (-2.3); = = -2math.ceil (' 2.7 '); = 3: Pure numeric string Math.ceil (' 2.7a '); = = NaN: Non-pure numeric string
Note: parameter: value {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {Number} returns the value after rounding. If the argument is not a number, the Nan is returned.
3, Math.floor (value): Rounding down a number, not rounded
Math.floor (2.7); = 2 Math.floor (2.3);//= 2 Math.floor ( -2.7);//= 3:-2.7 Rounding down returns-3 Math.floor ( -2.3);//=> ; -3 Math.floor (' 2.7 ');//+ = 2: Pure numeric string math.floor (' 2.7a ');//= = NaN: Non-pure numeric string
Note: parameter: value {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {Number} returns the value after rounding. If the argument is not a number, the Nan is returned.
4, Math.max (Value1,value2...valuen): Returns the maximum value in the parameter
Math.max (1, 2, 3, 4, 5); = 5 Math.max (1, 2, 3, 4, ' 5 ');//= 5 Math.max (1, 2, 3, 4, ' a ');//= = NaN
Note: parameter: Value1,value2.....valuen {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {Number} returns the maximum value. If a parameter is not a number, the Nan is returned.
5, Math.min (Value1,value2...valuen): Returns the smallest value in the parameter
Math.min (1, 2, 3, 4, 5); = 1 math.min (' 1 ', 2, 3, 4, 5);//= 1 math.min (1, 2, 3, 4, ' a ');//= = NaN
Note: parameter: Value1,value2.....valuen {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {Number} returns the maximum value. If a parameter is not a number, the Nan is returned.
6. Math.pow (x, y): Returns the Y-order of X
Math.pow (2, 3); = 8:2 of 3 square Math.pow (3, 2);//= 9:3 of the 2 Math.pow (' 4 ', 2);//= 16:4 of 2 math.pow (' 2a ', 2);// = NaN
Note: parameters: X, y {number | NUMBERSTR}: A string of numbers or pure numbers. Return value: {number} returns the Y-side of X. If a parameter is not a number, the Nan is returned.
7, Math.random (): Returns a pseudo-random number, greater than 0, less than 1.0
Math.random (); = 0.8982374747283757 math.random ();//= 0.39617531932890415 math.random (); 0.35413061641156673 math.random ();//= 0.054441051790490746
Note: parameter: No return value: {number} returns a pseudo-random, greater than 0, less than 1.0
8, Math.Round (value): Rounded after rounding
Math.Round (2.5); = 3 math.round (2.4);//= 2 math.round ( -2.6);//+ = 3 math.round ( -2.5);//+ = 2:-2.5 rounded to -2 Math.Round ( -2.4);//= 2 math.round (' 2.7 ');//+ = 3: Pure numeric string math.round (' 2.7a ');//= = NaN: Non-pure number Character string
Note: parameter: value {number | NUMBERSTR}: A string of numbers or pure numbers. return value: {integer} returns the integer after the parameter is rounded. If the argument is not a number, the Nan is returned.
9, Math.sqrt (value): Returns the square root of the parameter
Console.log (MATH.SQRT (9)); = 3 console.log (MATH.SQRT);//= 4 console.log (' math.sqrt ');//= 5 console.log (Ma Th.sqrt (' a ')); = NaN
Note: parameter: value {number | NUMBERSTR}: Numeric or purely numeric string return value: {number} returns the square root of the parameter
Js-math Object