number.md (1272B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function number 4 5 Create a number or convert a string, boolean, or unit to a number. 6 When value is a matrix, all elements will be converted to number. 7 8 9 ## Syntax 10 11 ```js 12 math.number(value) 13 math.number(unit, valuelessUnit) 14 ``` 15 16 ### Parameters 17 18 Parameter | Type | Description 19 --------- | ---- | ----------- 20 `value` | string | number | BigNumber | Fraction | boolean | Array | Matrix | Unit | null | Value to be converted 21 `valuelessUnit` | Unit | string | A valueless unit, used to convert a unit to a number 22 23 ### Returns 24 25 Type | Description 26 ---- | ----------- 27 number | Array | Matrix | The created number 28 29 30 ## Examples 31 32 ```js 33 math.number(2) // returns number 2 34 math.number('7.2') // returns number 7.2 35 math.number(true) // returns number 1 36 math.number([true, false, true, true]) // returns [1, 0, 1, 1] 37 math.number(math.unit('52cm'), 'm') // returns 0.52 38 ``` 39 40 41 ## See also 42 43 [bignumber](bignumber.md), 44 [boolean](boolean.md), 45 [complex](complex.md), 46 [index](index.md), 47 [matrix](matrix.md), 48 [string](string.md), 49 [unit](unit.md)