Common methods of JS Math object
A set of numbers to find the maximum minimum value
var Max=math.max (1,2,3,4,8,-9);//ask for maximum value
var min=math.min (1,2,3,4,8,-9);//Minimum value
Console.log (max,min);//return 8-9 Note: Nan is returned if a string appears in the argument
Take the whole
var num=18.1;
var num2=18.9;
Rounding up Math.ceil ()
Console.log (Math.ceil (num), Math.ceil (num2));//return 19 19
Take only integer Math.floor ()
Console.log (Math.floor (num), Math.floor (num2));//return 18 18
Rounding the rounding Math.Round
Console.log (Math.Round (num), Math.Round (num2));//return 18 19
Absolute Math.Abs ()
var num =-9;
var num1 = 9;
Console.log (Math.Abs (num), Math.Abs (NUM1));//both return 9
Generate random number Math.random ()
var random=math.random ();
Console.log (random);//Returns a floating-point number greater than 0 less than 1 by default;
A random number method that generates an integer between A and B
function Getrandom (A, b) {
var num = b-a+1;//number of random numbers
Return Math.floor (Math.random () *num+a);
}
Common methods of JS Math object