mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
59 lines
1.9 KiB
Markdown
59 lines
1.9 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-numeric">Function numeric <a href="#function-numeric" title="Permalink">#</a></h1>
|
|
|
|
Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.numeric(x)
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`value` | string | number | BigNumber | bigint | Fraction | A numeric value or a string containing a numeric value
|
|
`outputType` | string | Desired numeric output type. Available values: 'number', 'BigNumber', or 'Fraction'
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
number | BigNumber | bigint | Fraction | Returns an instance of the numeric in the requested type
|
|
|
|
|
|
<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
|
|
math.numeric('4') // returns 4
|
|
math.numeric('4', 'number') // returns 4
|
|
math.numeric('4', 'bigint') // returns 4n
|
|
math.numeric('4', 'BigNumber') // returns BigNumber 4
|
|
math.numeric('4', 'Fraction') // returns Fraction 4
|
|
math.numeric(4, 'Fraction') // returns Fraction 4
|
|
math.numeric(math.fraction(2, 5), 'number') // returns 0.4
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[number](number.html),
|
|
[fraction](fraction.html),
|
|
[bignumber](bignumber.html),
|
|
[bigint](bigint.html),
|
|
[string](string.html),
|
|
[format](format.html)
|