Home  >  Article  >  Web Front-end  >  How to use Math objects in JavaScript

How to use Math objects in JavaScript

不言
不言Original
2018-12-13 16:26:143012browse

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);".

How to use Math objects in JavaScript

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

How to use How to use How to use Math objects in JavaScript objects in JavaScript objects in JavaScript

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

How to use How to use Math objects in JavaScript objects in JavaScript

##Attribute 3. max(a,b,c,……. ,z) (get the maximum value)

Get the maximum value in a set of values


The code is as follows

<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

How to use How to use Math objects in JavaScript objects in JavaScript

Attribute 4. round() (get the rounded value)

Put the decimal in Within the brackets of round(), you can get the decimal rounded value

The 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

How to use Math objects in JavaScript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn