Javascript method to convert string to int: first create a code sample file; then convert the string into int through "var s = "32" var i = new Number(s) parseInt()" Can.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to convert string to int in javascript?
In javascript, string and int types must be converted to each other
Convert int type to string type in javascript
(1) var x=100 a = x.toString() (2) var x=100; a = x +""; //JS会自动隐性转换
javascript Convert string to int
JScript var s = "32" var i = new Number(s) parseInt() parseInt()
For example:
parseInt("abc") // Returns NaN. parseInt("12abc") // Returns 12. parseInt("12") //Return 12.
[Related recommendations: javascript advanced tutorial]
The above is the detailed content of How to convert string to int in javascript. For more information, please follow other related articles on the PHP Chinese website!