JavaScript parsefloat () method _javascript Tips

Source: Internet
Author: User

Definition and usage of the parsefloat () method:

The Parsefloat () method can parse a string and return a floating-point number.

Note: This method returns Nan if the first character in the string cannot be converted to a number. If a string contains more than one number, only the first number is returned.

Click to see more ECMAScript global methods and properties.

Syntax structure:

Copy Code code as follows:

Parsefloat (String)

Parameter list:

Parameters Describe
String Necessary. The string to be parsed.

Instance code:

Copy Code code as follows:

Console.log (parsefloat ("123"));

Output result: 123.

Copy Code code as follows:

Console.log (parsefloat ("123,321"));

Only the first number can be returned. Output result: 123.

Copy Code code as follows:

Console.log (parsefloat ("N321"));

The first character cannot be converted to a number. Output result: NaN.

Copy Code code as follows:

Console.log (Parsefloat ("12 Years old"));

Output Result: 12.

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.