A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString below:

BigInt.prototype.toString() - JavaScript | MDN

BigInt.prototype.toString()

Baseline Widely available

toString() 方法返回一个字符串,表示指定 BigInt 对象。后面的 "n" 不是字符串的一部分。

尝试一下
console.log(1024n.toString());
// Expected output: "1024"

console.log(1024n.toString(2));
// Expected output: "10000000000"

console.log(1024n.toString(16));
// Expected output: "400"
语法
bigIntObj.toString([radix])
参数
radix可选

可选,介于 2 到 36 之间的整数,指定用于表示数值的基数。

返回值

表示指定 BigInt 对象的字符串。

异常
RangeError

如果 toString() 的基数小于 2 或大于 36, 则抛出 RangeError。

描述

BigInt 对象重写 Object 对象的 toString() 方法;它不继承 Object.prototype.toString()。对于 BigInt 对象,toString() 方法返回指定基数中对象的字符串表示形式。

toString() 方法解析其第一个参数,并尝试返回指定基数 (base) 的字符串表示形式。对于大于 10 的参数,使用字母表中的字母表示大于 9 的数字。例如,对于十六进制数(以 16 为基数),使用 a 到 f。

如果未指定基数,则假定首选基数为 10。

如果 bigIntObj 为负,则保留符号。即使基数是 2,情况也是如此;返回的字符串是 bigIntObj 的正二进制表示,前面是一个 - 符号,而不是 bigIntObj 的两个补码。

示例 Using toString
17n.toString(); // '17'
66n.toString(2); // '1000010'
254n.toString(16); // 'fe'
-10n.toString(2); // -1010'
-0xffn.toString(2); // '-11111111'
Negative-zero BigInt

没有负零 BigInt,因为整数中没有负零。-0.0 是一个 IEEE 浮点概念,只出现在 JavaScript Number 类型中。

(-0n).toString(); // '0'
BigInt(-0).toString(); // '0'
规范 浏览器兼容性 请参阅

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4