1 |
|
2 |
|
3 | # Function unit
|
4 |
|
5 | Create a unit. Depending on the passed arguments, the function
|
6 | will create and return a new math.type.Unit object.
|
7 | When a matrix is provided, all elements will be converted to units.
|
8 |
|
9 |
|
10 | ## Syntax
|
11 |
|
12 | ```js
|
13 | math.unit(unit : string)
|
14 | math.unit(value : number, unit : string)
|
15 | ```
|
16 |
|
17 | ### Parameters
|
18 |
|
19 | Parameter | Type | Description
|
20 | --------- | ---- | -----------
|
21 | `args` | * | Array | Matrix | A number and unit.
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | Unit | Array | Matrix | The created unit
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | const a = math.unit(5, 'cm') // returns Unit 50 mm
|
34 | const b = math.unit('23 kg') // returns Unit 23 kg
|
35 | a.to('m') // returns Unit 0.05 m
|
36 | ```
|
37 |
|
38 |
|
39 | ## See also
|
40 |
|
41 | [bignumber](bignumber.md),
|
42 | [boolean](boolean.md),
|
43 | [complex](complex.md),
|
44 | [index](index.md),
|
45 | [matrix](matrix.md),
|
46 | [number](number.md),
|
47 | [string](string.md),
|
48 | [createUnit](createUnit.md)
|