Basic Math Applications in JavaScript objects

在前端项目的编程中,我们经常会需要运用到一些基本的数学方法。在JavaScript,Math对象灵活的运用可以帮我们很好地解决一些常见的数学问题。
下面是几个常见的Math对象和其使用方法的介绍:

1, Math.PI actual value is pi [pi]
2, Math.round () action which is the fractional part of the object and removed rounded
Example: console.log (Math.round (3.214)) ; // print result. 3
Console. log (Math.round (3.675)); // print result. 4
. 3, Math.random () takes random value between 0 and 1 (not including 0 and 1)
. 4, Math.ceil () takes an integer of upwardly
Example : console.log (Math.ceil (3.001)) ; // print result. 4
. 5, Math.floor () down to the nearest integer
Example: console.log (Math.floor (3.9999)) ; // print result 3
6, Math.max () returns the maximum target data
Example: console.log (Math.max (2,32,92,12,78,81)) ; // print result is 92
. 7, Math.min ( ) returns the minimum value of object data
Example: console.log (Math.min (2,32,92,12,78,81)) ; // print result is 2
NOTE: Math.max and accepted only Math.min could be a plurality of parameters, the array can not receive. Upon receipt of the array will be NaN.
8, x power Math.pow (a, x) of a computing
Example: console.log (Math.pow (2,3)) ; // print result. 8
. 9, the Math.sqrt (n) value of n is square rooter
Example: console.log (Math.sqrt (9)) ; // print result. 3
10, Math.sin, () operation trigonometric sinusoidal
Example: console.log (Math.sin (Math.PI)) // print result is 1 (sin90 °)
the cosine operator 11, Math.cos () for trigonometric functions
Example: console.log (Math.cos (Math.PI)) // print result is 0 (cos90 °)
Note: Math. sin Math.cos angle brackets and is received in radians.

Published an original article · won praise 0 · Views 78

Guess you like

Origin blog.csdn.net/X_LiPing/article/details/104740912
Recommended