mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
1.2 KiB
1.2 KiB
Function numeric
Convert a numeric input to a specific numeric type: number, BigNumber, or Fraction.
Syntax
math.numeric(x)
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
string | number | BigNumber | Fraction | A numeric value or a string containing a numeric value |
outputType |
string | Desired numeric output type. Available values: 'number', 'BigNumber', or 'Fraction' |
Returns
| Type | Description |
|---|---|
| number | BigNumber | Fraction | Returns an instance of the numeric in the requested type |
Examples
math.numeric('4') // returns number 4
math.numeric('4', 'number') // returns number 4
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 number 0.4