VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-number-parsefloat-method/

⇱ JavaScript Number parseFloat() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Number parseFloat() Method

Last Updated : 11 Jul, 2025

JavaScript parseFloat() Method is used to accept the string and convert it into a floating-point number. If the string does not contain a numeral value or If the first character of the string is not a Number then it returns NaN i.e, not a number. It actually returns a floating-point number parsed up to that point where it encounters a character that is not a Number. 

Syntax:

parseFloat(Value)

Parameters: This method accepts a single parameter.

  • value: This parameter obtains a string that is converted to a floating-point number.

Return value: It returns a floating-point Number and if the first character of a string cannot be converted to a number then the function returns NaN i.e, not a number.

Below is an example of the parseFloat() method:

Example 1: 

Output:

Using parseFloat("3.14") = 3.14 

Example 2: 

Output: The parseFloat() function ignores leading and trailing spaces and returns the floating point Number of the string.

parseFloat(" 100 ") = 100
parseFloat("2018@geeksforgeeks") = 2018
parseFloat("geeksforgeeks@2018") = NaN
parseFloat("3.14") = 3.14
parseFloat("22 7 2018") = 22

Example 3: Using the isNaN() function to test whether the converted values are a valid numbers or not. 

Output:

x is a number
y is not a number
Using parseInt("3.14") = 3
Using parseFloat("3.14") = 3.14

Supported Browsers:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Safari 1 and above
  • Opera 3 and above

We have a complete list of list, to know more about the numbers please go through that article.

Comment