JavaScript (ES2026) reference · Number Methods and Properties
JavaScript Number.parseFloat() Method
Parse a decimal number from the start of a string, ignoring trailing text. Same as the global parseFloat().
JavaScript (ES2026) Since ES2015
Syntax
Number.parseFloat(string)
Parameters
| Parameter | Description |
|---|---|
string |
The text to parse. |
Return value
A number or NaN.
Examples
console.log(Number.parseFloat("3.14 meters"), Number.parseFloat(".5"), Number.parseFloat("abc"));
Output
3.14 0.5 NaN
console.log(Number.parseFloat("12px"), Number("12px"));
Output
12 NaN
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
float()· Python
Related
Number.parseInt()· Parse an integer from the start of a string in a given base (radix). Always pass the radix, usually 10.parseFloat()· Parse a decimal number from the start of a string, stopping at the first character that can't be part of it.- JavaScript Numbers · tutorial
- JavaScript Type Conversion · tutorial