In js, Math functions can include various methods, such as Math. random (): Math. round (); Math. floor (); and Math. ceil (); opposite, Math. floor (); let me introduce it later.
Math functions are mainly used to process numbers.
Math. random (): Any decimal point between 0 and 1, for example, 0.0105901374530933 or 0.872525005541986.
Math. round (); returns the nearest integer in rounding mode.
Math. ceil (); is the nearest integer obtained from the top.
Math. floor (); opposite to Math. ceil (); Math. floor (); returns the nearest integer.
Math. round (Math. random ());
This expression can generate a number between 0.0 and 1.0, and then round it to get an integer. The generated number is 0 or 1. This expression can be used when 50% of the expressions are available.
Math. sqrt (): square root. If it is not of the numerical type, a NaN is returned.
Math. pow (a, B): a is the base number, and B is the index.
Example
The Code is as follows: |
Copy code |
Var a = 6.448; Var B = 9; Document. write ("into an integer:" + Math. ceil (a) + "<br/> "); Document. write ("end-to-end INTEGER:" + Math. floor (a) + "<br/> "); Document. write ("rounded to integer:" + Math. round (a) + "<br/> "); Document. write ("Return minimum value:" + Math. min (a, B) + "<br/> "); Document. write ("return maximum value:" + Math. max (a, B) + "<br/> "); Document. write ("power, B power of a:" + Math. pow (a, B) + "<br/> "); Document. write ("generate a random number between 0 and 1:" + Math. random () + "<br/> "); Document. write ("square:" + Math. sqrt (B) + "<br/> "); |