JavaScript parseFloat() Function
The parseFloat() function reads a decimal number from the start of a string and ignores anything after it.
Description
The parseFloat() function parses the start of a string as a decimal number, stopping at the first character that can't be part of one, so parseFloat('1.5rem') is 1.5. It understands exponents like 1e3 and Infinity, but not hexadecimal. If the string doesn't start with a number, it returns NaN. Use Number() when the whole string must be a valid number.
It's the global version of Number.parseFloat(), and both are the same function. Only a dot is recognized as the decimal separator, so numbers formatted for locales that use a comma, such as "3,5", are read as 3.
It's commonly used to read the numeric part of CSS values from getComputedStyle(), which returns strings like "16px". To get an integer instead, use parseInt() with a radix.
Syntax
parseFloat(string)Parameters
- stringThe value to parse. Leading white space is ignored.
Return Value
A floating point number parsed from the start of the string, or NaN.
Example
Browser Support
The following information will show you the current browser support for the parseFloat() function. Hover over a browser icon to see the version that first introduced support for this function.
Desktop





Tablets & Mobile





