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/bigint/tostring/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/bigint/tostring/index.html (limited to 'files/ja/web/javascript/reference/global_objects/bigint/tostring') diff --git a/files/ja/web/javascript/reference/global_objects/bigint/tostring/index.html b/files/ja/web/javascript/reference/global_objects/bigint/tostring/index.html new file mode 100644 index 0000000000..06d956f1ed --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/bigint/tostring/index.html @@ -0,0 +1,95 @@ +--- +title: BigInt.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/BigInt/toString +tags: + - BigInt + - JavaScript + - Method + - Prototype + - toString() +translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/toString +--- +
{{JSRef}}
+ +

toString()メソッドは、指定した {{jsxref("BigInt")}} オブジェクトを表す文字列を返します。末尾の "n" は返り値の文字列の一部にはなりません。

+ +
{{EmbedInteractiveExample("pages/js/bigint-tostring.html")}}
+ + + +

構文

+ +
bigIntObj.toString([radix])
+ +

パラメーター

+ +
+
radix{{optional_inline}}
+
オプション。数値を表す底に指定する 2 以上 36 以下の整数(基数)。
+
+ +

戻り値

+ +

指定した {{jsxref("BigInt")}} オブジェクトを表す文字列。

+ +

例外

+ +
+
{{jsxref("RangeError")}}
+
toString() が 2 未満または 36 より大きな基数を与えられた場合、{{jsxref("RangeError")}} がスローされます。
+
+ +

説明

+ +

{{jsxref("BigInt")}} オブジェクトは {{jsxref("Object")}} の toString() メソッドをオーバーライドします。つまり、{{jsxref("Object.prototype.toString()")}} を継承しません。{{jsxref( "BigInt")}} オブジェクトでは、toString() メソッドは指定された基数によるオブジェクトの文字列表現を返します。

+ +

toString() メソッドは 1 番目の引数を解析し、指定された基数(底)による文字列表現を返そうとします。10 より大きな基数が指定された場合は、アルファベットが 9 より大きな数値を示します。例えば、16 進数(底が 16)では a から f が使用されます。

+ +

radix が指定されなかった場合は、基数として 10 が指定されたとみなします。

+ +

bigIntObj が負の数だった場合、符号は保持されます。これは、基数が 2 だった場合にも適用されます。つまり、返り値の文字列は、bigIntObj の正の 2 進数表現の先頭に - 符号が付いたものであり、bigIntObj の 2 の補数ではありません。

+ +

+ +

toStringの使用

+ +
17n.toString();      // '17'
+66n.toString(2);     // '1000010'
+254n.toString(16);   // 'fe'
+-10n.toString(2);    // -1010'
+-0xffn.toString(2);  // '-11111111'
+
+ +

BigInt における負の 0

+ +

整数に負の 0 が存在しないのと同様に、BigInt には負の 0 がありません。-0.0 は JavaScript の {{jsxref("Number")}} 型にのみ現れる、IEEE 浮動小数点数の概念です。

+ +
(-0n).toString();      // '0'
+BigInt(-0).toString(); // '0'
+ +

仕様

+ + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-bigint.prototype.tostring', 'BigInt.prototype.toString()')}}
+ +

ブラウザー実装状況

+ + + +

{{Compat("javascript.builtins.BigInt.toString")}}

+ +

関連情報

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