函数 numeric #

将数字输入转换为特定的数字类型:number、BigNumber、bigint 或 Fraction。

Syntax #

math.numeric(x)
math.numeric(value, outputType)

Parameters #

Parameter Type Description
value string | number | BigNumber | bigint | Fraction 数字值或包含数字值的字符串
outputType string 所需的数字输出类型。可用值:“number”、“BigNumber” 或 “Fraction”

Returns #

Type Description
number | BigNumber | bigint | Fraction 返回请求类型的数字实例

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

另请参阅 #

numberfractionbignumberbigintstringformat

Fork me on GitHub