The parseFloat () method parses a string and returns a floating point number. This article will share with you the knowledge about the javascriptparsefloat () method. if you are interested in the javascriptparsefloat method, join us and learn it.
ParseFloat () method definition and usage:
The parseFloat () method parses a string and returns a floating point number.
Note: If the first character in a string cannot be converted to a number, NaN is returned. If the string contains multiple numbers, but only the first number is returned.
Click here to view more global methods and attributes of ECMAScript.
Syntax structure:
The code is as follows:
ParseFloat (string)
Parameter list:
| Parameters |
Description |
| String |
Required. The string to be parsed. |
Instance code:
The code is as follows:
Console. log (parseFloat ("123 "));
Output result: 123.
The code is as follows:
Console. log (parseFloat ("123,321 "));
Only the first number can be returned. Output result: 123.
The code is as follows:
Console. log (parseFloat ("N321 "));
The first character cannot be converted to a number. Output result: NaN.
The code is as follows:
Console. log (parseFloat ("12 Years Old "));
Output result: 12.