内置方法

内置方法可以直接调用。

  1. parseInt
    /**
  • Converts A string to an integer.
  • @param s A string to convert into a number.
  • @param radix A value between 2 and 36 that specifies the base of the number in numString.
  • If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
  • All other strings are considered decimal.
    */
    declare function parseInt(s: string, radix?: number): number;
    把字符串按照对应的进制转化为数字。得到的数字是10进制,radix是说字符串的进制。
var s = '110';

console.log(parseInt(s, 2));
console.log(parseInt(s, 10));
console.log(parseInt(s, 4));

6
110
20

你可能感兴趣的:(内置方法)