From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/number/parseint/index.html | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html b/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html new file mode 100644 index 0000000000..56f1d834be --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html @@ -0,0 +1,82 @@ +--- +title: Number.parseInt() +slug: Web/JavaScript/Reference/Global_Objects/Number/parseInt +tags: + - ECMAScript 2015 + - JavaScript + - Method + - Number +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseInt +--- +
{{JSRef}}
+ +

概述

+ +

Number.parseInt() 方法依据指定基数 [ 参数 radix 的值],把字符串 [ 参数 string 的值] 解析成整数。

+ +

语法

+ +
Number.parseInt(string[, radix])
+
+ +

参数

+ +

{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Parameters")}} 

+ +

参数string:要解析的值。 如果此参数不是字符串,则使用ToString抽象操作将其转换为字符串。忽略此参数中的前导空格。
+ 参数radix:一个介于2到36之间的整数,代表字符串的基数(数学数字系统中的基)。小心-这并不是默认为10。

+ +

返回值

+ +

{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Return value")}}

+ +

从给定字符串中解析的整数。如果基数小于11,且第一个非空白字符不能转换为数字,则返回NaN。

+ +

描述

+ +

这个方法和全局的 {{jsxref("parseInt", "parseInt()")}} 函数具有一样的函数功能:

+ +
Number.parseInt === parseInt; // true
+ +

ECMAScript 2015添加了这部分 (其目的是对全局变量进行模块化). 请另见 {{jsxref("parseInt", "parseInt()")}} 获取更多详情和示例.

+ +

Polyfill

+ +
if (Number.parseInt === undefined) {
+    Number.parseInt = window.parseInt;
+}
+ +

说明

+ + + + + + + + + + + + + + + + + + + +
说明状态评论
{{SpecName('ES2015', '#sec-number.parseint', 'Number.parseInt')}}{{Spec2('ES2015')}}初始定义.
{{SpecName('ESDraft', '#sec-number.parseint', 'Number.parseInt')}}{{Spec2('ESDraft')}}
+ +

浏览器兼容性

+ +

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

+ +

{{Compat("javascript.builtins.Number.parseInt")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf