Math object Properties
- Math.E: Returns the arithmetic constant E, the base of the natural logarithm (approximately 2.718)
- Math.ln2: Returns the natural logarithm of 2 (approximately 0.693)
- Math.ln10: Returns the natural logarithm of 10 (approximately equal to 2.302)
- Math.log2e: Returns the logarithm base 2 of e (approximately equal to 1.414)
- Math.log10e: Returns the logarithm base 10 of e (approximately equal to 0.434)
- Math.pi: Returns PI (approximately equal to 3.14159)
- Math.sqrt1_2: returns the reciprocal of the square root of 2 (approximately equal to 0.707)
- Math.sqrt2: Returns the square root of 2 (approximately equal to 1.414)
Math object methods
- Abs (a) : Returns the absolute value
// Return absolute value<script type = "text/javascript" > alert(Math.abs(-6)); // The result is 6
</script>
Copy the code
- Ceil (a) : round up
// round up<script type = "text/javascript" > alert(Math.ceil(3.1)); // The result is 4
</script>
Copy the code
- Floor (a) : round down
// round down<script type = "text/javascript" > alert(Math.floor(3.9)); // The result is 3
</script>
Copy the code
- Round (a) : round
// Round off<script type = "text/javascript" > alert(Math.round(3.4)); // The result is 3
</script>
<script type = "Text/javascript">
alert(Math.round(3.5)); // The result is 4
</script>
Copy the code
- Log (a) : the natural log of a
- Min (a,b) : Returns the smaller numbers of a and b
// Return the smaller numbers of a and b<script type = "text/javascript" > alert(Math.min(5.8)); // The result is 5
</script>
Copy the code
- Max (a,b) : Returns the greater number of a and b
// Return the larger numbers of a and b<script type = "text/javascript" > alert(Math.max(5.8)); // The result is 8
</script>
Copy the code
- Pow (a,n) : a to the NTH power
// A to the n<script type = "text/javascript" > alert(Math.pow(2.5)); // The result is 32
</script>
Copy the code
- Random () : generate random number, interval [0,1]
// generate random number, interval [0,1]<script type = "text/javascript" > alert(Math.random( ));
</script>
Copy the code
- SQRT (a) : square root
/ / square root<script type = "text/javascript" > alert(Math.sqrt( 4)); // The result is 2
</script>
Copy the code
- Sine (radians) : the value of sine
// Find the sine of 90 degrees<script type = "text/javascript" > alert(Math.sin(90* Math.PI/180)); // The result is 1
</script>
Copy the code
- Cosine (radians) : cosine
/ / cosine values<script type = "text/javascript" > alert(Math.cos(180* Math.PI/180)); // The result is 1
</script>
Copy the code
- Tan (radians) : tangent value
- Asin (a) : arcsine
- Acos (a) : inverse cosine
- Atan (radians) : Arctangent value