Favorites

JavaScript parseFloat() Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
parseFloat()
JavaScript Global functionThis function is supported by all modern browsers.
Updated 28th November 2026

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

console.log(parseFloat('3.14'));
console.log(parseFloat('1.5rem'));
console.log(parseFloat('  2e3 '));
console.log(parseFloat('px10'));

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee