1 |
|
2 |
|
3 | # Function to
|
4 |
|
5 | Change the unit of a value.
|
6 |
|
7 | For matrices, the function is evaluated element wise.
|
8 |
|
9 |
|
10 | ## Syntax
|
11 |
|
12 | ```js
|
13 | math.to(x, unit)
|
14 | ```
|
15 |
|
16 | ### Parameters
|
17 |
|
18 | Parameter | Type | Description
|
19 | --------- | ---- | -----------
|
20 | `x` | Unit | Array | Matrix | The unit to be converted.
|
21 | `unit` | Unit | Array | Matrix | New unit. Can be a string like "cm" or a unit without value.
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | Unit | Array | Matrix | value with changed, fixed unit.
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.to(math.unit('2 inch'), 'cm') // returns Unit 5.08 cm
|
34 | math.to(math.unit('2 inch'), math.unit(null, 'cm')) // returns Unit 5.08 cm
|
35 | math.to(math.unit(16, 'bytes'), 'bits') // returns Unit 128 bits
|
36 | ```
|
37 |
|
38 |
|
39 | ## See also
|
40 |
|
41 | [unit](unit.md)
|