JavaScript (ES2026) reference · JSON and Global Functions
JavaScript parseFloat() Function
Parse a decimal number from the start of a string, stopping at the first character that can't be part of it.
JavaScript (ES2026) Since ES1
Syntax
parseFloat(string)
Parameters
| Parameter | Description |
|---|---|
string |
The text to parse. |
Return value
A number or NaN.
Examples
console.log(parseFloat("3.5kg"), parseFloat("1e3"), parseFloat("kg3.5"));
Output
3.5 1000 NaN
console.log(parseFloat("1,5"), Number("1,5".replace(",", ".")));
Output
1 1.5
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
float()· Python
Related
Number.parseFloat()· Parse a decimal number from the start of a string, ignoring trailing text. Same as the global parseFloat().parseInt()· Parse an integer from the start of a string in a given base. Always pass the radix, e.g. parseInt("08", 10).- JavaScript Type Conversion · tutorial