What are the operation methods of JavaScript Math function
This article mainly explains "what are the operation methods of JavaScript Math function". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the operation methods of JavaScript Math function".
Ceil,floor,sin,cos operation of JavaScript Math function
Math.ceil ()
The return value of Math.ceil (x) is the nearest integer rounded on x:
Example
Math.ceil (6.4); / / returns 7
Math.floor ()
The return value of Math.floor (x) is the nearest integer rounded under x:
Example
Math.floor (2.7); / / returns 2
Math.sin ()
Math.sin (x) returns the sine of the angle x in radians (a value between-1 and 1).
If you want to use angles instead of radians, you need to convert angles to radians:
Angle in radians = Angle in degrees x PI / 180.
Example
Math.sin (90 * Math.PI / 180); / / returns 1 (90-degree sine)
Math.cos ()
Math.cos (x) returns the cosine of the angle x in radians (a value between-1 and 1).
If you want to use angles instead of radians, you need to convert angles to radians:
Angle in radians = Angle in degrees x PI / 180.
Example
Math.cos (0 * Math.PI / 180); / / returns 1 (cosine of 0 degrees)
Thank you for your reading, these are the contents of "what are the operating methods of the JavaScript Math function?" after the study of this article, I believe you have a deeper understanding of the operation of the JavaScript Math function, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!