There are also some properties and methods for built-in Math mathematical constants and functions. For example, the PI attribute of the Math object will have the attribute value pi (3.141...), and you can call it like this:
Math.PI
Similarly, standard mathematical functions are also Math's methods. These include trigonometric functions, logarithms, exponents, and other functions. For example, if you want to use the trigonometric function sin, you can write it like this:
Math.sin(1.56)
It should be noted that all trigonometric parameters of Math are radian systems.
Unlike other objects, you cannot create your own Math object. You can only use built-in Math objects.
eg:
1.min( ) and max( )
var value = [1,2,3,4,5,6,7,8];var max = Math.max.apply(Math, values);
2. Rounding method
Math.ceil(): Round upward
Math.floor(): round down
Math.round(): rounded
3.random( )
The Math.random( ) method returns a random number between 0 and 1, excluding 0 and 1
var num = Math.floor(Math.random()*10, + 1)//Returns the number between 1-10
4.round()
How to use round().
<html><body><script type="text/javascript">document.write(Math.round(0.60) + "<br />")document.write(Math.round(0.50) + "<br />")document.write(Math.round(0.49) + "<br />")document.write(Math.round(-4.40) + "<br />")document.write(Math.round(-4.60))</script></body></html>
5.random()
How to use random() to return random numbers between 0 and 1.
<html><body><script type="text/javascript">document.write(Math.random())</script></body></html>