The Math object is an intrinsic object of JavaScript, and its purpose is to perform common arithmetic tasks. This object is not used like a Date,array object
New keyword to get the object, but direct Math. [{Property|method}], if an attempt to create with new is an error, because the object was created by the engine when the script engine was loaded.
The Math object itself is nothing to struggle with, just know how to use it.
Let's take a look at the intrinsic 8 properties of the Math Object E property, Pi property, SQRT2 property, Sqrt1_2 property, LN2 property, LN10 attribute, log2e attribute, log10e attribute they correspond to constant, pi, 2 square root, 1/2 square root, 2 The natural logarithm of 10, the logarithm of the natural logarithm of 2, and the logarithm of e of the base 10. The Math. Properties are available when using specific
And then there are some common methods of math objects.
The 1,round () method returns the nearest integer to the given number, which is the rounding of our primary school, but if it is negative, the result is to convert the negative numbers to integers, and then add the minus sign after the calculation, given an example below
Code document. Write (Math. Round (0.60) + "<br/>"); document. Write (Math. Round (0.50) + "<br/>"); document. Write (Math. Round (0.49) + "<br/>"); document. Write (Math. Round ( -4.40) + "<br/>"); document. Write (Math. Round (-4.60)); 110-4-5
The 2,random () method returns a pseudo-random number between 0 and 1, excluding 0 and 1, which we can also use to generate random numbers in development, given an example
Code var value=Math. Random (); document. Write (Value.charat (3));
With each run of the code above, we can get a random number between 0 and 9, including 0 and 9
The 3,max () method returns the larger of the 0 or more numeric expressions given, if no argument is given, the return value equals Negative_infinity. If there is a parameter of Nan, the return value is still nan.
Code var value=Math. Max (6,3,7,8,8); document. Write (value);
The 4,min () method returns the smaller values in the given 0 or more numeric expressions. If no argument is given, the return value equals Positive_infinity. If there is a parameter of Nan, the return value is also Nan.
Code var value=Math. Min (6,3,7,8,8); document. Write (value);
There are many other methods of the math object, such as the ABS () method, the Asin () method, which are not often used, and are used to refer to the document.
If there is anything wrong with the article, please point out.
JavaScript Math Object