Today, we used parseFloat (the first parameter, 10) in jquery. We didn't know what the second parameter meant. So I checked it online and wrote it down if I forgot it later.
Definition and usage: The parseFloat () function parses a string and returns a floating point number.
Syntax: parseFloat (string). The string parameter is required, indicating the string to be parsed.
Return Value: return the parsed number.
Notes:
1. spaces at the beginning and end are allowed.
2. If the first character of a string cannot be converted to a number, parseFloat () returns NaN
3. If you only want to parse the integer part of a number, use the parseInt () method.
4. Only the first digit in the string will be returned.
Attached example:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Document. write (parseFloat ("10 "))
Document. write (parseFloat ("10.00 "))
Document. write (parseFloat ("10.33 "))
Document. write (parseFloat ("34 45 66 "))
Document. write (parseFloat ("60 "))
Document. write (parseFloat ("40 years "))
Document. write (parseFloat ("He was 40 "))
</Script>
Output in sequence:
10
10
10.33
34
60
40
NaN
Next, let's talk about the second question: what does "10" in parseFloat (the first parameter, 10) mean? The second parameter of parseFloat indicates the hexadecimal conversion, and "10" indicates the conversion to "10 ".