Methods for Numbers in JavaScript

1.random

Syntax: Math.random()
Function: Get a random number between 0 and 1, including 0, not including 1

var num = Math.random()

console.log(num)

2.round

Syntax: Math.round()
Function: Round the data to an integer

var num = Math.round(1.5)

console.log(num)  //---> 2

3.ceil

Syntax: Math.ceil()
Function: round up the data

var num = Math.ceil(1.0000001)

console.log(num)  //---> 2

4.floor

Syntax: Math.floor()
Function: Round the data down

var num = Math.floor(1.9999999)

console.log(num)  //---> 1

5.abs

Syntax: Math.abs()
Function: Take the absolute value of the data

var num = Math.absj(-1)

console.log(num)  //---> 1

6.sqrt

Syntax: Math.sqrt()
Function: find square root

var num = Math.sqrt(16)

console.log(num)  //---> 4

7.pow

Syntax: Math.pow(data 1, data 2)
Function: Find the x power of a base number

var num = Math.pow(2,3)

console.log(num)  //---> 8

8.max

Syntax: Math.max(data 1, data 2, data 3...)
Function: Find the maximum value in the parameters

var num = Math.max(100,20,300,4,5000)

console.log(num)  //---> 5000

9.min

Syntax: Math.min(data 1, data 2, data 3...)
Function: Find the minimum value in the parameters

var num = Math.min(100,20,300,4,5000)

console.log(num)  //---> 4

10.PI

Syntax: Math.PI
Function: find the minimum value in the parameters

var num = Math.PI

console.log(num)  //---> 3.1415926......

Guess you like

Origin blog.csdn.net/weixin_48649246/article/details/127552569