mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
59 lines
1.5 KiB
Markdown
59 lines
1.5 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
|
|
|
<h1 id="function-unit">Function unit <a href="#function-unit" title="Permalink">#</a></h1>
|
|
|
|
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.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.unit(unit : string)
|
|
math.unit(value : number, unit : string)
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`args` | * | Array | Matrix | A number and unit.
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Unit | Array | Matrix | The created unit
|
|
|
|
|
|
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```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
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[bignumber](bignumber.html),
|
|
[boolean](boolean.html),
|
|
[complex](complex.html),
|
|
[index](index.html),
|
|
[matrix](matrix.html),
|
|
[number](number.html),
|
|
[string](string.html),
|
|
[createUnit](createUnit.html)
|