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

See also #

number, fraction, bignumber, string, format

Fork me on GitHub