Introduction to parameter setting of ParseInt function

  • 2020-03-30 01:10:18
  • OfStack

We often use the ParseInt function to convert a string to an int value. The ParseInt function has two parameters to set, the second of which can be default.

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

Base parameter optional & PI; 16, 8, 10, 2.

Usually we use base 10, it is best to always use the second parameter, and set it to 10, without the second parameter, the function to determine how to choose the base. (there may be problems, such as "070" ECMAScript 3 being octal ECMAScript 5 being decimal)


Related articles: