parseFloat()
Parses a string and returns a floating-point number.
Syntax
parseFloat(string)
Returns
number — The parsed number, or `NaN` if none could be parsed.
Examples
console.log(parseFloat("3.14abc"));
console.log(parseFloat(" 2.5e3 "));
Output
3.14
2500
console.log(parseFloat(".5"));
console.log(parseFloat("12.34.56"));
Output
0.5
12.34
console.log(parseFloat("xyz"));
Output
NaN
Notes
- Parses as much of a valid float as possible, ignoring trailing junk.
- Does not take a radix; only base 10 is supported.
- Use `Number()` for strict full-string numeric conversion.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |