Home > Web Front-end > JS Tutorial > Introduction to ParseInt function parameter setting_Basic knowledge

Introduction to ParseInt function parameter setting_Basic knowledge

WBOY
Release: 2016-05-16 17:05:49
Original
1710 people have browsed it

We often use the ParseInt function to convert strings into int values. The ParseInt function has two parameters that can be set, and the second parameter can be defaulted.

ParseInt("string", base used)

var num1=ParseInt("10",2)///2

var num1=ParseInt("10",8)///8

var num1=ParseInt("10",10)//10

var num1=ParseInt("10",16)//16

The base parameters are optional: 16, 8, 10, and 2.

We usually use base 10. It is best to always use the second parameter and set it to 10. If there is no second parameter, the function will decide how to choose the base. (Problems may occur, for example, "070" is considered octal by ECMAScript 3 and decimal by ECMAScript 5)

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