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