---
layout: default
---
Function unit #
Create a unit. Depending on the passed arguments, the function
will create and return a new math.Unit object.
When a matrix is provided, all elements will be converted to units.
Syntax #
```js
math.unit(unit : string)
math.unit(value : number, unit : string)
```
Parameters #
Parameter | Type | Description
--------- | ---- | -----------
`args` | * | Array | Matrix | A number and unit.
Returns #
Type | Description
---- | -----------
Unit | Array | Matrix | The created unit
Throws #
Type | Description
---- | -----------
Examples #
```js
const a = math.unit(5, 'cm') // returns Unit 50 mm
const b = math.unit('23 kg') // returns Unit 23 kg
a.to('m') // returns Unit 0.05 m
```
See also #
[bignumber](bignumber.html),
[boolean](boolean.html),
[complex](complex.html),
[index](index.html),
[matrix](matrix.html),
[number](number.html),
[string](string.html),
[createUnit](createUnit.html)