The JavaScript number parseFloat() method is used to convert a string into a floating point number. It will throw NaN exception if specified can not be converted into float number.
Syntax:
Number.parseFloat(string)
Parameters
string: It represents the string which have to be converted into floating point number.
Returns
Floating point number.
Example
<!DOCTYPE html> <html> <body> <script> var n= 12.334; document.writeln(Number.parseFloat("50.5FIVE")); </script> </body> </html> |
Output
50.5 |