Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The parseFloat() function parses a string argument and returns a floating point number.
The value to parse, coerced to a string. Leading whitespace in this argument is ignored.
A floating point number parsed from the given string, or NaN when the first non-whitespace character cannot be converted to a number.
Note: JavaScript does not have the distinction of "floating point numbers" and "integers" on the language level. parseInt() and parseFloat() only differ in their parsing behavior, but not necessarily their return values. For example, parseInt("42") and parseFloat("42") would return the same value: a Number 42.
The parseFloat function converts its first argument to a string, parses that string as a decimal number literal, then returns a number or NaN. The number syntax it accepts can be summarized as:
Syntax-wise, parseFloat() parses a subset of the syntax that the Number() function accepts. Namely, parseFloat() does not support non-decimal literals with 0x, 0b, or 0o prefixes but supports everything else. However, parseFloat() is more lenient than Number() because it ignores trailing invalid characters, which would cause Number() to return NaN.
Similar to number literals and Number(), the number returned from parseFloat() may not be exactly equal to the number represented by the string, due to floating point range and inaccuracy. For numbers outside the -1.7976931348623158e+308 – 1.7976931348623158e+308 range (see Number.MAX_VALUE), -Infinity or Infinity is returned.
The following examples all return 3.14:
The following example returns NaN:
Anecdotally, because the string NaN itself is invalid syntax as accepted by parseFloat(), passing "NaN" returns NaN as well.
Infinity values are returned when the number is outside the double-precision 64-bit IEEE 754-2019 format range:
Infinity is also returned when the string starts with "Infinity" or "-Infinity":
parseFloat() does not handle BigInt values. It stops at the n character, and treats the preceding string as a normal integer, with possible loss of precision. If a BigInt value is passed to parseFloat(), it will be converted to a string, and the string will be parsed as a floating-point number, which may result in loss of precision as well.
You should pass the string to the BigInt() function instead, without the trailing n character.
| ECMAScript® 2027 Language Specification # sec-parsefloat-string |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.