UNPKG

1.27 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function number
4
5Create a number or convert a string, boolean, or unit to a number.
6When value is a matrix, all elements will be converted to number.
7
8
9## Syntax
10
11```js
12math.number(value)
13math.number(unit, valuelessUnit)
14```
15
16### Parameters
17
18Parameter | Type | Description
19--------- | ---- | -----------
20`value` | string &#124; number &#124; BigNumber &#124; Fraction &#124; boolean &#124; Array &#124; Matrix &#124; Unit &#124; null | Value to be converted
21`valuelessUnit` | Unit &#124; string | A valueless unit, used to convert a unit to a number
22
23### Returns
24
25Type | Description
26---- | -----------
27number &#124; Array &#124; Matrix | The created number
28
29
30## Examples
31
32```js
33math.number(2) // returns number 2
34math.number('7.2') // returns number 7.2
35math.number(true) // returns number 1
36math.number([true, false, true, true]) // returns [1, 0, 1, 1]
37math.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)