Home > Web Front-end > JS Tutorial > Definition, usage and precautions of parseFloat (parameter 1, parameter 2) in js_Basic knowledge

Definition, usage and precautions of parseFloat (parameter 1, parameter 2) in js_Basic knowledge

WBOY
Release: 2016-05-16 17:42:39
Original
1681 people have browsed it

Today when I was looking at jquery, parseFloat (the first parameter, 10) was used. I never understood what the second parameter meant, so I checked it online and wrote it down in case I forgot it later.

Definition and usage: The parseFloat() function parses a string and returns a floating point number.

Syntax: parseFloat(string), the parameter string is required and represents the string to be parsed
Return value: Returns the parsed number

Notes:
1. Leading and trailing spaces are allowed.
2. If the first character of the string cannot be converted to a number, then parseFloat() will return NaN
3. If you only want to parse the integer part of the number, use the parseInt() method.
4. Only the first number in the string will be returned.

Attached example:

Copy code The code is as follows:



Output in sequence:
10
10
10.33
34
60
40
NaN
Let’s talk about the second question: What does 10 in parseFloat (first parameter, 10) mean? parseFloat The second parameter represents the base of conversion. 10 means conversion to base 10.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template