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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

parseFloat(string)

Parameters

ParameterDescription
string The text to parse.

Return value

A number or NaN.

Examples

Parse decimalsTry it yourself
console.log(parseFloat("3.5kg"), parseFloat("1e3"), parseFloat("kg3.5"));

Output

3.5 1000 NaN
Comma decimals need convertingTry it yourself
console.log(parseFloat("1,5"), Number("1,5".replace(",", ".")));

Output

1 1.5

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?