Javascript data type conversion string Integer Conversion

Source: Internet
Author: User

JavaScript there are two types of data conversion methods: one is to convert the entire value from one type to another data type (called basic Data type conversion ), another method is to extract another type of value from one value and complete the conversion.

basic data type conversion three methods:

1. convert to string type: string (). For example, the result of string (678) is "678"
2. convert to numeric: Number (). For example, the result of number ("678") is 678
3. convert to boolean: Boolean (); example: Boolean ("AAA ") the result is true

extract another type of value from one value. method:

1. extract the integer in the string: parseint (); example: parseint ("123 Zhang ") the result is 123
2. extract the floating point in the string: parsefloat (); example: parsefloat ("0.55 Zhang ") result 0.55

3. Execute a segment represented by a stringJavascriptCode: Eval (); example: Zhang = eval ("1 + 1") Result: Zhang = 2


Both functions are fault tolerant. For example, "123abc" will change to 123.

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.