How does javascript convert strings into numbers and javascript strings?

Source: Internet
Author: User

How does javascript convert strings into numbers and javascript strings?

How to convert a string to a number in javascript:
It may be used to convert a string to a number, especially in an environment involving digital computing. The following describes how to convert a string.
1). Convert the parseInt () function:
This function can parse a string and return an integer.
The code example is as follows:

 

ParseInt ("12px"); // returns 12 parseInt ("0xA"); // returns 10 parseInt ("2.3"); // returns 2 parseInt ("blue "); // return NaN

 

For more information, see section 1 of the parseInt () function in JavaScript.
2). Convert the parseFloat () function:
The conversion method of this function is similar to that of the parseInt () function, except that it can return a decimal floating point number, and the parseFloat () function does not have a base mode.
The code example is as follows:

 

ParseFloat ("12px"); // returns 12 parseFloat ("0xA"); // returns 0 parseFloat ("2.3"); // returns 2.3 parseFloat ("blue "); // return NaN

 

For more information, see section 1 of parseFloat () method in JavaScript.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 8239.

For more information, see: http://www.softwhy.com/javascript/

 

Related Article

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.