The parseFloat() function parses an argument (converting it to a string first if needed) and returns a floating point number.

Try it





The value to parse, coerced to a string. Leading whitespace in this argument is ignored.

Return value

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.


parseFloat is a function property of the global object.

  • If parseFloat encounters a character other than a plus sign (+), minus sign (- U+002D HYPHEN-MINUS), numeral (09), decimal point (.), or exponent (e or E), it returns the value up to that character, ignoring the invalid character and characters following it.
  • A second decimal point also stops parsing (characters up to that point will still be parsed).
  • Leading spaces in the argument are ignored.
  • If the argument's first character can't be converted to a number (it's not any of the above characters), parseFloat returns NaN.
  • parseFloat() can also parse and return Infinity or -Infinity if the string starts with "Infinity" or "-Infinity" preceded by none or more white spaces.
  • For numbers outside the -1.7976931348623158e+308 - 1.7976931348623158e+308 range -Infinity or Infinity is returned.
  • parseFloat converts BigInt syntax to Numbers, losing precision. This happens because the trailing n character is discarded.

Consider Number(value) for stricter parsing, which converts to NaN for arguments with invalid characters anywhere.

parseFloat will parse non-string objects if they have a toString or valueOf method. The returned value is the same as if parseFloat had been called on the result of those methods.


parseFloat returning a number

The following examples all return 3.14:

parseFloat('  3.14  ');
parseFloat('3.14some non-digit characters');
parseFloat({ toString() { return "3.14" } });

parseFloat returning NaN

The following example returns NaN:


Returning infinity

Infinity values are returned when the number is outside the double-precision 64-bit IEEE 754-2019 format range:

parseFloat('1.7976931348623159e+308');  //  Infinity
parseFloat('-1.7976931348623159e+308'); // -Infinity

Interaction with BigInt values

The following examples both return 900719925474099300, losing precision as the integer is too large to be represented as a float:



ECMAScript Language Specification
# sec-parsefloat-string

Browser compatibility

BCD tables only load in the browser

See also