Summary of front-end Math attribute methods

Description of Math

Math is a built-in object that has some mathematical constant properties and mathematical function methods. Math is not a function object.

Math Use Number Type. No support BigInt.

Unlike other global objects, Math is not a constructor. All properties and methods of Math are static. The writing method of quoting pi is Math.PI, the writing method of calling sine and cosine function is Math.sin(x), x is the parameter to be passed in. The constants for Math are defined using full-precision floating point numbers in JavaScript.

1. Math.ceil round up

const a = '4.4'
    console.log('Math.ceil', Math.ceil(a)) // 5

 2. Math.floor rounds down

const a = '4.4'
    console.log('Math.floor', Math.floor(a)) // 4

3.Math.round rounding

const a = '4.6'
    console.log('Math.round', Math.round(a)) // 5

4. Math.random 0-1 random number

console.log('Math.random', Math.random())

5.Math.max maximum value 

Summary of front-end array methods-CSDN Blog

6.Math.min minimum value 

Summary of front-end array methods-CSDN Blog

7.Math.abs absolute value

const a = '-4.6'
    console.log('Math.abs', Math.abs(a)) // 4.6

8. Math.sqrt square root

const a = '9'
    console.log('Math.sprt', Math.sqrt(a)) // 3

9. Math.pow exponentiation

const a = '3'
    console.log('Math.pow', Math.pow(a,2)) // 9

10. Math.trunc integer part

const a = '4.5'
    console.log('整数部分', Math.trunc(a)) // 4

11.Math.PI

function calculateCircumference(radius) {
  return 2 * Math.PI * radius;
}

calculateCircumference(1); // 6.283185307179586

12.Math.clz32()

console.log('获取相应的内容', Math.clz32(1000000))  // 12

13.Math.sign() Determine whether it is a positive/negative number

console.log(Math.sign(3)); //  1
    console.log(Math.sign(-3)); // -1
    console.log(Math.sign("-3")); // -1
    console.log(Math.sign(0)); //  0
    console.log(Math.sign(-0)); // -0
    console.log(Math.sign(NaN)); // NaN
    console.log(Math.sign("foo")); // NaN
    console.log(Math.sign()); // 

Guess you like

Origin blog.csdn.net/2201_75705263/article/details/134560676