Explanation of the second parameter in JS parsefloat (first argument, second argument)

Source: Internet
Author: User

Today, when I was looking at jquery, I used the parsefloat (the first parameter, 10), I didn't know what the second parameter meant, so I looked it up on the internet, so I forgot to turn it down later.

Definition and Usage: the parsefloat () function resolves a string and returns a floating-point number.

Syntax: parsefloat (String), parameter string is required, representing the string to be parsed

Return value: Returns the parsed number

Precautions:

1. The opening and closing spaces are allowed.

2. If the first character of a string cannot be converted to a number, then parsefloat () returns NaN

3. If you want to parse only the integer part of a number, use the parseint () method.

4. Only the first number in a string is returned.

Attached examples:

<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 ("Years"))

document.write (parsefloat ("He was 40"))

</script>

Output in turn:

10

10

10.33

34

60

40

NaN

Here's a second question: What does 10 in parsefloat (the first argument, 10) mean

The second parameter of the parsefloat represents the binary of the conversion, and 10 translates to a 10 binary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.