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

Convert string to int in js to convert String type into int type_javascript skills

WBOY
Release: 2016-05-16 16:39:45
Original
1590 people have browsed it

When I was working on a project today, I encountered a problem. I needed to convert a String type variable into an int type. As usual, I wrote var i = Integer.parseInt("112"); but the console reported an error saying "'Integer' is undefined". Later, I learned that the conversion of String to int in js is different from that in Java, and you cannot directly use the conversion from Java to js. Change it to var j = parseInt("11"); and it will be ok.

Remarks: Whether it is Java or JavaScript, the parseInt method has two parameters. The first parameter is the object to be converted, and the second parameter is the base, which can be 2, 8, 10, 16. The default is Decimal processing. But in JavaScript, numbers starting from 0 are considered to be processed using octal system, and numbers starting from 0x are considered to be processed using hexadecimal system

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!