Parse different values:
parseFloat(10);
parseFloat("10");
parseFloat("10.33");
parseFloat("34 45 66");
parseFloat("He was 40");
Try it Yourself »
More examples below.
The 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.
parseFloat(
value)
Parameter | Description |
value | Required. The value to parse. |
Type | Description |
A number | NaN if no number is found. |
parseFloat()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Parse different values:
parseFloat("40.00");
parseFloat(" 40 ");
parseFloat("40 years");
parseFloat("40H")
parseFloat("H40");
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!