Function numeric #
Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
Syntax #
math.numeric(x)
math.numeric(value, outputType)
Parameters #
| 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’ | 
Returns #
| Type | Description | 
|---|---|
| number | BigNumber | bigint | Fraction | Returns an instance of the numeric in the requested type | 
Throws #
Type | Description —- | ———–
Examples #
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