Parses the argument as an integer number and returns it:
将参数解析为整数并返回:
Number.parseInt('10') //10
Number.parseInt('10.00') //10
Number.parseInt('237,21') //237
Number.parseInt('237.21') //237
Number.parseInt('12 34 56') //12
Number.parseInt(' 36 ') //36
Number.parseInt('36 is my age') //36
As you can see Number.parseInt()
is pretty flexible. It can also convert strings with words, extracting the first number, but the string must start with a number:
如您所见, Number.parseInt()
非常灵活。 它还可以用单词转换字符串,提取第一个数字,但是字符串必须以数字开头:
Number.parseInt('I am Flavio and I am 36') //NaN
You can add a second parameter to specify the radix. Radix 10 is default but you can use octal or hexadecimal number conversions too:
您可以添加第二个参数以指定基数。 Radix 10是默认值,但您也可以使用八进制或十六进制数字转换:
Number.parseInt('10', 10) //10
Number.parseInt('010') //10
Number.parseInt('010', 8) //8
Number.parseInt('10', 8) //8
Number.parseInt('10', 16) //16