函数 boolean #
创建一个布尔值,或将字符串或数字转换为布尔值。对于数字,非零数字返回 true,零返回 false。字符串可以是 'true' 或 'false',或者包含数字。当值为矩阵时,所有元素都将转换为布尔值。
Syntax #
math.boolean(x)
Parameters #
| Parameter | Type | Description |
|---|---|---|
value |
string | number | boolean | Array | Matrix | null | 任何类型的任意值 |
Returns #
| Type | Description |
|---|---|
| boolean | Array | Matrix | 布尔值 |
Throws #
Type | Description —- | ———–
Examples #
math.boolean(0) // returns false
math.boolean(1) // returns true
math.boolean(-3) // returns true
math.boolean('true') // returns true
math.boolean('false') // returns false
math.boolean([1, 0, 1, 1]) // returns [true, false, true, true]