Home  >  Article  >  Web Front-end  >  How to convert string to int in javascript

How to convert string to int in javascript

藏色散人
藏色散人Original
2021-06-30 10:08:5315958browse

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.

How to convert string to int in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn