![]() |
VOOZH | about |
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.
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:
We have a complete list of list, to know more about the numbers please go through that article.