Definition and usage of the parsefloat () method:
The Parsefloat () method can parse a string and return a floating-point number.
Note: This method returns Nan if the first character in the string cannot be converted to a number. If a string contains more than one number, only the first number is returned.
Click to see more ECMAScript global methods and properties.
Syntax structure:
Copy Code code as follows:
Parameter list:
Parameters |
Describe |
String |
Necessary. The string to be parsed. |
Instance code:
Copy Code code as follows:
Console.log (parsefloat ("123"));
Output result: 123.
Copy Code code as follows:
Console.log (parsefloat ("123,321"));
Only the first number can be returned. Output result: 123.
Copy Code code as follows:
Console.log (parsefloat ("N321"));
The first character cannot be converted to a number. Output result: NaN.
Copy Code code as follows:
Console.log (Parsefloat ("12 Years old"));
Output Result: 12.