Number.parseFloat()

Number.parseFloat() 静态方法解析参数并返回浮点数。如果无法从参数中解析数字,则返回 NaN

¥The Number.parseFloat() static method parses an argument and returns a floating point number. If a number cannot be parsed from the argument, it returns NaN.

Try it

语法

¥Syntax

js
Number.parseFloat(string)

参数

¥Parameters

string

要解析的值,强制为字符串。该参数中的前导 whitespace 将被忽略。

返回值

¥Return value

从给定的 string 解析出的浮点数。

¥A floating point number parsed from the given string.

或者当第一个非空白字符无法转换为数字时为 NaN

¥Or NaN when the first non-whitespace character cannot be converted to a number.

示例

¥Examples

Number.parseFloat 与 parseFloat

¥Number.parseFloat vs. parseFloat

该方法与全局 parseFloat() 函数具有相同的功能:

¥This method has the same functionality as the global parseFloat() function:

js
Number.parseFloat === parseFloat; // true

其目的是全局变量的模块化。

¥Its purpose is modularization of globals.

有关更多详细信息和示例,请参阅 parseFloat()

¥See parseFloat() for more detail and examples.

规范

Specification
ECMAScript Language Specification
# sec-number.parsefloat

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看