JavaScript Number.parseFloat()
Examples
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 »
Definition and Usage
The Number.parseFloat() method parses a value as a string and returns the first number.
Notes
If the first character cannot be converted, NaN is returned.
Leading and trailing spaces are ignored.
Only the first number found is returned.
Syntax
Number.parseFloat(value)
Parameters
| Parameter | Description |
| value | Required. The value to parse. |
Return Value
| Type | Description |
| Number | NaN if no number is found. |
Browser Support
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).