JavaScript parseFloat()
Examples
Parse different values:
parseFloat(10);
parseFloat("10");
parseFloat("10.33");
parseFloat("34 45 66");
parseFloat("He was 40");
Try it Yourself »
More examples below.
Description
The 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
parseFloat(value)
Parameters
Parameter | Description |
value | Required. The value to parse. |
Return Value
Type | Description |
A number | NaN if no number is found. |
Browser Support
parseFloat()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
More Examples
Parse different values:
parseFloat("40.00");
parseFloat(" 40 ");
parseFloat("40 years");
parseFloat("40H")
parseFloat("H40");
Try it Yourself »