According to the name, this object is used for numerical calculation. I have referred to the content of the Javascript development user manual, which contains a rich set of content and many development skills. It is estimated that one post will not end, I will post frequently-used skills in the follow-up posts. Please pay attention to it...
Math object
Is an inherent object that provides basic mathematical functions and constants.
Here I will only introduce the commonly used methods. Please refer to the following...
Method 1: ABS: returns the absolute value of a number.
Example:
<SCRIPT>
Alert (math. Abs (-111 ));
</SCRIPT>
Method 2: The floor method returns the largest integer smaller than or equal to the value parameter (but I prefer to refer to the ending number after the decimal point)
<SCRIPT>
Alert (math. Floor (52.63); // return 52
</SCRIPT>
Method 3: Ceil method: returns the smallest integer greater than or equal to its numeric parameter. (But I prefer to rounding it out)
<SCRIPT>
Alert (math. Ceil (52.63); // return 53
</SCRIPT>
Method 4: The Max method returns the greater of zero or multiple numeric expressions. (Here, we should note that the number of objects allowed is quite high. I think this method is quite cool. You can remember that I mentioned the method with the maximum value when talking about the array Object last time, it is implemented using a built-in method in the sort method. If you forget it, check it out .)
<SCRIPT>
Alert (math. Max (100, 100,); // is returned.
</SCRIPT>
Method 5: min: return a smaller value in zero or multiple numeric expressions.
<SCRIPT>
Alert (math. Min (100,); // 3 is returned.
</SCRIPT>
Method 6: pow method: return the specified power of the base expression.
<SCRIPT>
Alert (math. Pow (1000); // returns to the power of 10.
</SCRIPT>
Method 7: the random method returns a pseudo-random number between 0 and 1.
<SCRIPT>
Alert (math. Random ());
</SCRIPT>
Method 8: The round method returns the nearest integer to the given numeric expression. (This method integrates the ceil method and the floor method, which is very easy to use and is strongly recommended)
<SCRIPT>
Alert (math. Round (52.66); // return 53
</SCRIPT>
<SCRIPT>
Alert (math. Round (52.36); // return 52
</SCRIPT>
Method 9: SQRT: returns the square root of a number.
<SCRIPT>
Alert (math. SQRT (100); // returns 10
</SCRIPT>
Okay. Now, I have finished all the common math methods, and there are some special ways to perform the positive cosine operation. I will not talk about it here. The following are some examples to illustrate the application scenarios. Please keep an eye on it...