首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Number.parseInt

Number.parseInt()方法可以根据给定的进制数把一个字符串解析成整数。

语法

代码语言:javascript
复制
Number.parseInt(string,[ radix ])

参数

string要解析的值。如果string参数不是一个字符串,那么它将被转换为一个字符串(使用ToString抽象操作)。字符串参数中的空白字符将被忽略。radix表示上述字符串的基数(数学数字系统中的基数)的2到36之间的整数。指定10人类通常使用的十进制数字系统。始终指定此参数以消除读者的困惑并保证可预测的行为。没有指定基数时,不同的实现会产生不同的结果,通常默认值为10。

返回值

从给定字符串解析的整数 如果第一个字符不能转换为数字,则返回NaN

描述

该方法和全局的?parseInt()函数是同一个函数:

代码语言:javascript
复制
Number.parseInt === parseInt; // true

请移步全局函数?parseInt()页面查看更多的解释和示例。

Polyfill

代码语言:javascript
复制
if (Number.parseInt === undefined)
    Number.parseInt = window.parseInt;

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Number.parseInt' in that specification.

Standard

Initial definition.

ECMAScript Latest Draft (ECMA-262)The definition of 'Number.parseInt' in that specification.

Living Standard

?

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

25

No

(Yes)

9

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

25

No

(Yes)

9

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com