mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
49 lines
1011 B
Markdown
49 lines
1011 B
Markdown
# Function unit
|
|
|
|
Create a unit. Depending on the passed arguments, the function
|
|
will create and return a new math.type.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
|
|
|
|
|
|
## Examples
|
|
|
|
```js
|
|
var a = math.unit(5, 'cm'); // returns Unit 50 mm
|
|
var b = math.unit('23 kg'); // returns Unit 23 kg
|
|
a.to('m'); // returns Unit 0.05 m
|
|
```
|
|
|
|
|
|
## See also
|
|
|
|
[bignumber](bignumber.md),
|
|
[boolean](boolean.md),
|
|
[complex](complex.md),
|
|
[index](index.md),
|
|
[matrix](matrix.md),
|
|
[number](number.md),
|
|
[string](string.md)
|
|
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|