Home > Article > Web Front-end > How to use Math objects in JavaScript
The How to use How to use Math objects in JavaScript objects in JavaScript object in JavaScript is a built-in function that can use the How to use How to use Math objects in JavaScript objects in JavaScript object to perform numerical calculations. Its usage syntax is such as "console.log(How to use How to use Math objects in JavaScript objects in JavaScript.PI);".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The How to use How to use Math objects in JavaScript objects in JavaScript object in JavaScript is a built-in function. You can use the How to use How to use Math objects in JavaScript objects in JavaScript object to perform numerical calculations. The How to use How to use Math objects in JavaScript objects in JavaScript object can directly call properties and methods to perform calculations. There is no need to use new to create an object. Let’s do this below. Take a look at the specific content,
Call of How to use How to use Math objects in JavaScript objects in JavaScript object attributes
Attribute 1. PI (get pi)
Since there is no need to create an object, we Just use
The code is as follows
<!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <title>JavaScript</title> </head> <body> <script> console.log(How to use How to use Math objects in JavaScript objects in JavaScript.PI); </script> </body> </html>
The operation effect is as follows: We can get the specific value of pi
Attribute 2. sqrt() (get the value under the root sign)
Get the value of the root sign of the value placed in the brackets of sqrt()
The code is as follows
<script> console.log(How to use How to use Math objects in JavaScript objects in JavaScript.sqrt(36)); </script>
The operation effect is as follows: the value of the root number of 36 is obtained
##Attribute 3. max(a,b,c,……. ,z) (get the maximum value)
Get the maximum value in a set of values<script> console.log(How to use How to use Math objects in JavaScript objects in JavaScript.max(5,6,7,2,9,10,1,3)); </script>The operation effect is as follows: Obtain this The largest number in a set of numbers
Attribute 4. round() (get the rounded value)
Put the decimal in Within the brackets of round(), you can get the decimal rounded valueThe code is as follows<script> console.log(How to use How to use Math objects in JavaScript objects in JavaScript.round(33.25461)); console.log(How to use How to use Math objects in JavaScript objects in JavaScript.round(89.62332)); </script>The running result is as follows In the How to use How to use Math objects in JavaScript objects in JavaScript object There are other attributes and methods that can perform various operations. You can use them according to your own needs. For more exciting content about JavaScript, you can pay attention to the JavaScript
Video Tutorial column of the php Chinese website! ! !
The above is the detailed content of How to use Math objects in JavaScript. For more information, please follow other related articles on the PHP Chinese website!