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

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

Syntax

Number.parseFloat(string)

Parameters

ParameterDescription
string The text to parse.

Return value

A number or NaN.

Examples

Parse a leading numberTry it yourself
console.log(Number.parseFloat("3.14 meters"), Number.parseFloat(".5"), Number.parseFloat("abc"));

Output

3.14 0.5 NaN
parseFloat() vs Number()Try it yourself
console.log(Number.parseFloat("12px"), Number("12px"));

Output

12 NaN

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?