SoFunction
Updated on 2025-04-06

Introduction to ParseInt function parameter settings

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

ParseInt("String", used by the binary)

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 binary parameters are optional 16, 8, 10, and 2.

Usually we use decimal system, it is best to always use the second parameter and set it to 10. If the second parameter is not set, the function will judge by itself how to select the binary system. (Problems may arise, such as "070" ECMAScript 3 considers octal, ECMAScript 5 considers decimal)