Powers and roots: math.pow (), math.sqrt ()

Round up and round down: math.ceil (), math.floor ()

Math.round()

A number can be rounded to an integer
    <script>
        console.log(Math.round(3.4));  / / 3
        console.log(Math.round(3.5));  / / 4
        console.log(Math.round(3.98));  / / 4
        console.log(Math.round(3.49));  / / 3
    </script>
Copy the code

         var a = 2.6548;
        console.log(Math.round(a*100) /100); / / 2.65
Copy the code
Math. Max (), and Math. The min ()

Math.max() gets the maximum value of the argument list

Math.min() gets the minimum value of the argument list

         console.log(Math.max(6.2.9.3));  / / 9
        console.log(Math.min(6.2.9.3));   / / 2
Copy the code

Use math.max () to maximize the array

Math.max() requires arguments to be “listed”, not arrays

The apply method specifies the context and passes in an array of “stray values” as arguments to the function

         var  arr = [3.6.9.2];
        var max = Math.max.apply(null,arr);
        console.log(max);  / / 9
        
          // In ES6, the maximum value of an array can be written as follows
        console.log(Math.max(... arr));/ / 9
Copy the code

Random number Math. The random ()

Math.random() yields decimal numbers between 0 and 1

To get integers in the interval [a,b], use the formula: parseInt(math.random ()*(b-a+1))+a

        // To generate integers within [a,b], use the formula parseInt(math.random ()*(b-a+1))+a
        / / [3]
        console.log(parseInt(Math.random()*(8-3+1)) +3);
Copy the code