1. Math. min () and Math. max () return the minimum and maximum values of the parameters respectively.
Example:
Alert (Math. min (1, 2, 3) // output "1"
Alert (Math. max (1, 2, 3) // output "3"
2. Math. abs () returns the absolute value of the parameter.
Example:
Alert (Math. abs (-1) // output "1"
3. Math. random () generates a random number ranging from 0 to 1.
Example:
Window. open ("http: // www. ***. com/index.shtml? T = "+ Math. random) // Add a parameter after the url address with the value of" Number "to ensure that the page is pulled from the server every time, instead of reading the cache.
4. Math. floor (), Math. round (), Math. ceil ()
Math. floor (): round down the decimal point to an integer. Example: alert (Math. floor (1.5) // output "1"
Math. round (): round the decimal number to an integer. Example: alert (Math. round (1.5) // output "2"
Math. ceil (): round up the decimal point to an integer. Example: alert (Math. round (1.5) // output "2"
Using these three functions is very convenient when it involves decimal calculation. For example, the following function is designed for decimal processing.
Copy codeThe Code is as follows:
Function test (num, flag, bit) // The number of decimals to be passed in (-1, down; 0, standard; 1) "flag" Reserved decimal digits "bit"
{
Var n = Math. pow (10, bit );
Switch (flag)
{
Case-1: return Math. floor (num * n)/n; break;
Case 0: return Math. round (num * n)/n; break;
Case 1: return Math. ceil (num * n)/n;
}
}