In js, string to int converts String type to int type, stringint

Source: Internet
Author: User

In js, string to int converts String type to int type, stringint

When I was working on the project today, I encountered a problem. I need to convert the String type variable to the int type. As usual, I wrote var I = Integer. parseInt ("112"), but the console reports an error saying "'integer' is not defined ". Later, I learned that the conversion of String to int in js is different from that in Java, and Java cannot be used directly in js. Change to var j = parseInt ("11"); then OK.

Note: Both Java and JavaScript have two parameters. The first parameter is the object to be converted, and the second parameter is the base number of the base number, which can be 2, 8, 10, 16. The default value is 10. however, in JavaScript, numbers starting with 0 are considered to be processed in octal mode, while 0x numbers are considered to be processed in hexadecimal mode.


How to convert string to int type in js

ParseInt ()

Java forced type conversion String to int, and int to String data is a number

Int intA = 10;
String StrB = "12 ";
Int c = Integer. parseInt (StrB); // converts String to int
String d = String. valueOf (intA); // convert int to String

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.