UNPKG

1.04 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function unit
4
5Create a unit. Depending on the passed arguments, the function
6will create and return a new math.type.Unit object.
7When a matrix is provided, all elements will be converted to units.
8
9
10## Syntax
11
12```js
13math.unit(unit : string)
14math.unit(value : number, unit : string)
15```
16
17### Parameters
18
19Parameter | Type | Description
20--------- | ---- | -----------
21`args` | * &#124; Array &#124; Matrix | A number and unit.
22
23### Returns
24
25Type | Description
26---- | -----------
27Unit &#124; Array &#124; Matrix | The created unit
28
29
30## Examples
31
32```js
33const a = math.unit(5, 'cm') // returns Unit 50 mm
34const b = math.unit('23 kg') // returns Unit 23 kg
35a.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)