JavaScriptParseFloat () method_javascript skills

Source: Internet
Author: User
The parseFloat () method parses a string and returns a floating point number. This article will share with you the knowledge about the javascriptparsefloat () method. if you are interested in the javascriptparsefloat method, join us and learn it. ParseFloat () method definition and usage:

The parseFloat () method parses a string and returns a floating point number.

Note: If the first character in a string cannot be converted to a number, NaN is returned. If the string contains multiple numbers, but only the first number is returned.

Click here to view more global methods and attributes of ECMAScript.

Syntax structure:

The code is as follows:


ParseFloat (string)

Parameter list:

Parameters Description
String Required. The string to be parsed.

Instance code:

The code is as follows:


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

Output result: 123.

The code is as follows:


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

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

The code is as follows:


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

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

The code is 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.