Home  >  Article  >  Web Front-end  >  Math,Number

Math,Number

PHP中文网
PHP中文网Original
2017-07-14 18:10:231186browse

①Math.trunc()

Math.trunc() method is used to remove the decimal part of a number and return the integer part.

When the parameter is a non-numeric value, the Math.trunc() method will first use Number() to convert it into a numerical value. If the integer part of the value cannot be obtained, such as a string or NaN or a null value, it will return NaN.

②Math.sign()

Math.sign() method is used to determine whether a number is positive, negative or 0
(1) If the parameter is a positive number, +1
is returned (2) If the parameter is a negative number, -1
is returned (3) If the parameter is 0, return 0
(4) The parameter is -0 and returns -0
(5) Other values ​​return NaN

③Math.cbrt()

Math.cbrt() method is used to calculate the cube root of a number

If the parameter is not a numerical value, Math.cbrt() also first uses the Number() method to convert it into a numerical value.
Conversion failure returns NaN.

Number.isNaN() is used to check whether a value is NaN.

Number.isNaN(NaN) // true
Number.isNaN(15) // false
Number.isNaN('15') // false
Number.isNaN(true) // false
Number.isNaN(9/NaN) // true
Number.isNaN('true'/0) // true
Number.isNaN('true'/'true') // true

Number.isInteger() is used to determine whether a value is an integer.

Number.isInteger(25) // true
Number.isInteger(25.0) // true
Number.isInteger(25.1) // false
Number.isInteger("15") // false
Number.isInteger(true) // false

The above is the detailed content of Math,Number. 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