Number.parseFloat()

Parses a string argument and returns a floating point number.

Since ES2015 Spec ↗

Syntax

Number.parseFloat(string)

Parameters

NameTypeRequiredDescription
string string Yes The value to parse. Leading whitespace is ignored.

Returns

number — The parsed number, or NaN if the string cannot start a number.

Examples

console.log(Number.parseFloat('3.14abc'));
Output
3.14
console.log(Number.parseFloat('  .5px'), Number.parseFloat('x'));
Output
0.5 NaN

Notes

Parses as much of the leading numeric portion as possible and ignores trailing garbage. Identical to the global `parseFloat`; the Number version exists for modularity.

Browser & runtime support

EnvironmentSince version
chrome 34
firefox 25
safari 9
edge 12
node 0.12

See also