JS parsefloat (parameter 1, parameter 2) definition and usage and precautions _ basics

Source: Internet
Author: User
Today in the time to see jquery used in the parsefloat (the first parameter, 10), has not understood what the second parameter means, so the Internet to check a bit, afraid of forgetting to write down.

Definitions and usages: the parsefloat () function parses a string and returns a floating-point number.

Syntax: parsefloat (String), parameter string is required to represent the string to be resolved
Return value: Returns the parsed number

Attention Matters
1. The opening and closing spaces are allowed.
2. If the first character of the string cannot be converted to a number, then parsefloat () returns NaN
3. If you want to resolve only the integer portion of a number, use the parseint () method.
4. Only the first digit in the string is returned.

attached examples
Copy Code code 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 ("Years"))
document.write (Parsefloat ("He is 40"))
</script>

output sequentially
10
10
10.33
34
60
40
NaN
Here's the second question: What do you mean by 10 in parsefloat (first argument, 10)? The second parameter of the parsefloat represents the transformation of the system, and 10 represents the transition to 10.

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.