hasNumericValue 函数 #
测试一个值是否为数字值。
对于字符串,如果字符串包含数值,则返回 true。
Syntax #
math.hasNumericValue(x)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
* | 要测试的值 |
Returns #
| Type | Description |
|---|---|
| boolean | 当 x 是 number、BigNumber、Fraction、Boolean 或包含数字的 String 时,返回 true。对于其他类型,返回 false。在未知类型的情况下抛出错误。 |
Throws #
Type | Description —- | ———–
Examples #
math.hasNumericValue(2) // returns true
math.hasNumericValue('2') // returns true
math.isNumeric('2') // returns false
math.hasNumericValue(0) // returns true
math.hasNumericValue(math.bignumber('500')) // returns true
math.hasNumericValue(math.bigint('42')) // returns true
math.hasNumericValue(42n) // returns true
math.hasNumericValue(math.fraction(4)) // returns true
math.hasNumericValue(math.complex('2-4i')) // returns false
math.hasNumericValue(false) // returns true
math.hasNumericValue([2.3, 'foo', false]) // returns [true, false, true]