数值 #
创建一个数字,或将字符串、布尔值或单位转换为数字。当值为矩阵时,所有元素都将被转换为数字。
Syntax #
math.number(value)
math.number(unit, valuelessUnit)
Parameters #
| Parameter | Type | Description |
|---|---|---|
value |
string | number | BigNumber | Fraction | boolean | Array | Matrix | Unit | null | 要转换的值 |
valuelessUnit |
Unit | string | 无量纲单位,用于将单位转换为数字 |
Returns #
| Type | Description |
|---|---|
| number | Array | Matrix | 创建的数字 |
Throws #
Type | Description —- | ———–
Examples #
math.number(2) // returns number 2
math.number('7.2') // returns number 7.2
math.number(true) // returns number 1
math.number([true, false, true, true]) // returns [1, 0, 1, 1]
math.number(math.unit('52cm'), 'm') // returns 0.52
另请参阅 #
bignumber, bigint, boolean, numeric, complex, index, matrix, string, unit