Number.parseFloat(10);
Number.parseFloat("10");
Number.parseFloat("10.33");
Number.parseFloat("34 45 66");
Number.parseFloat("He was 40");
Try it Yourself »
Number.parseFloat("40.00");
Number.parseFloat(" 40 ");
Number.parseFloat("40 years");
Number.parseFloat("40H")
Number.parseFloat("H40");
Try it Yourself »
The Number.parseFloat()
method parses a value as a string and returns the first number.
If the first character cannot be converted, NaN
is returned.
Leading and trailing spaces are ignored.
Only the first number found is returned.
Number.parseFloat(
value)
Parameter | Description |
value | Required. The value to parse. |
Type | Description |
Number | NaN if no number is found. |
Number.parseFloat()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Number.parseFloat()
is not supported in Internet Explorer 11 (or earlier).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!