The parseFloat() function parses an argument and returns a floating-point number.
Example
parseFloat() Syntax
The syntax of the parseFloat() function is:
parseFloat(string)
parseFloat() Parameters
The parseFloat() function takes in:
- string - The value to parse. If it is not a string, it is converted to one using
ToStringabstract operation.
Note: Leading whitespace characters are ignored.
parseFloat() Return Value
- Returns a floating-point number parsed from the given string.
- Returns
NaNwhen the first non-whitespace character can't be converted to a number.
Example: Using parseFloat()
Output
10 3.14 3.14 127 NaN 464546416543075600
Notes:
parseFloat()will parse non-string objects if they have atoStringorvalueOfmethod.parseFloat()stops converting a string to float when it encounters a non-numeric character.
Recommended Reading: Javascript parseInt()