Home > Web Front-end > JS Tutorial > body text

How to convert string to int in javascript

藏色散人
Release: 2021-06-30 10:08:53
Original
15977 people have browsed it

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会自动隐性转换
Copy after login

javascript Convert string to int

JScript
var s = "32"
var i = new Number(s)
parseInt()
parseInt()
Copy after login

For example:

parseInt("abc") // Returns NaN.
parseInt("12abc") // Returns 12.
parseInt("12") //Return 12.
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template