// Numbers with a leading 0 used a radix of 8 (octal) before ECMAScript 5.
// These days, browsers will treat '0101' as decimal.
var result = parseInt('0101');
// Numbers that start with 0x use a radix of 16 (hexidecimal)
var result = parseInt('0x0101');
// Numbers starting with anything else assumes a radix of 10
var result = parseInt('101');
// Or you can specify the radix, in this case 2 (binary)
var result = parseInt('0101', 2);
基数参数用于指定
which numeral system to be used, for
example, a radix of 16 (hexadecimal)
indicates that the number in the
string should be parsed from a
从十六进制数到十进制数
号码。
如果基数参数被省略,
JavaScript 假设:
如果字符串以“0x”开头,则
基数是16(十六进制)
If the string begins with "0", the
基数是8(八进制)。这个特性是
deprecated
The parseInt() function parses a string and returns an integer. It takes a second argument for the 基, which 指定字符串中数字的基数. The 基 can be an integer between 2 and 36.