参考 float()

float()

Converts a String to a floating point (decimal) Number.

float() converts strings that resemble numbers, such as '12.34', into numbers.

The parameter, str, is the string value to convert. For example, calling float('12.34') returns the number 12.34. If an array of strings is passed, as in float(['12.34', '56.78']), then an array of numbers will be returned.

Note: If a string can't be converted to a number, as in float('giraffe'), then the value NaN (not a number) will be returned.

示例

语法

float(str)
float(ns)

参数

str
String:

string to convert.

ns
String[]:

array of strings to convert.

Returns

Number: converted number.
Notice any errors or typos? Please let us know. Please feel free to edit src/utilities/conversion.js and open a pull request!

相关参考