1 |
|
2 |
|
3 | # Function numeric
|
4 |
|
5 | Convert a numeric input to a specific numeric type: number, BigNumber, or Fraction.
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.numeric(x)
|
12 | ```
|
13 |
|
14 | ### Parameters
|
15 |
|
16 | Parameter | Type | Description
|
17 | --------- | ---- | -----------
|
18 | `value` | string | number | BigNumber | Fraction | A numeric value or a string containing a numeric value
|
19 | `outputType` | string | Desired numeric output type. Available values: 'number', 'BigNumber', or 'Fraction'
|
20 |
|
21 | ### Returns
|
22 |
|
23 | Type | Description
|
24 | ---- | -----------
|
25 | number | BigNumber | Fraction | Returns an instance of the numeric in the requested type
|
26 |
|
27 |
|
28 | ## Examples
|
29 |
|
30 | ```js
|
31 | math.numeric('4') // returns number 4
|
32 | math.numeric('4', 'number') // returns number 4
|
33 | math.numeric('4', 'BigNumber') // returns BigNumber 4
|
34 | math.numeric('4', 'Fraction') // returns Fraction 4
|
35 | math.numeric(4, 'Fraction') // returns Fraction 4
|
36 | math.numeric(math.fraction(2, 5), 'number') // returns number 0.4
|
37 | ```
|
38 |
|
39 |
|
40 | ## See also
|
41 |
|
42 | [number](number.md),
|
43 | [fraction](fraction.md),
|
44 | [bignumber](bignumber.md),
|
45 | [string](string.md),
|
46 | [format](format.md)
|