diff options
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects/bigint/tostring/index.html')
-rw-r--r-- | files/ko/web/javascript/reference/global_objects/bigint/tostring/index.html | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/global_objects/bigint/tostring/index.html b/files/ko/web/javascript/reference/global_objects/bigint/tostring/index.html new file mode 100644 index 0000000000..3b04cd9f84 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/bigint/tostring/index.html @@ -0,0 +1,102 @@ +--- +title: BigInt.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/BigInt/toString +tags: +- BigInt +- JavaScript +- Method +- Prototype +- toString() +browser-compat: javascript.builtins.BigInt.toString +--- +<div>{{JSRef}}</div> + +<p>The <strong><code>toString()</code></strong> method returns a string representing the + specified {{jsxref("BigInt")}} object. The trailing "n" is not part of the string.</p> + +<div>{{EmbedInteractiveExample("pages/js/bigint-tostring.html")}}</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="brush: js"> +toString() +toString(radix) +</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>radix</code>{{optional_inline}}</dt> + <dd>Optional. An integer in the range 2 through 36 specifying the base to use for + representing numeric values.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>A string representing the specified {{jsxref("BigInt")}} object.</p> + +<h3 id="Exceptions">Exceptions</h3> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>If <code>toString()</code> is given a radix less than 2 or greater than 36, a + {{jsxref("RangeError")}} is thrown.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<p>The {{jsxref("BigInt")}} object overrides the <code>toString()</code> method of the + {{jsxref("Object")}} object; it does not inherit + {{jsxref("Object.prototype.toString()")}}. For {{jsxref( "BigInt")}} objects, the + <code>toString()</code> method returns a string representation of the object in the + specified radix.</p> + +<p>The <code>toString()</code> method parses its first argument, and attempts to return a + string representation in the specified radix (base). For radixes above 10, the letters + of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers + (base 16) <code>a</code> through <code>f</code> are used.</p> + +<p>If the <code>radix</code> is not specified, the preferred radix is assumed to be 10. +</p> + +<p>If the <code>bigIntObj</code> is negative, the sign is preserved. This is the case even + if the radix is 2; the string returned is the positive binary representation of the + <code>bigIntObj</code> preceded by a <code>-</code> sign, <strong>not</strong> the two's + complement of the <code>bigIntObj</code>.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Using_toString">Using <code>toString</code></h3> + +<pre class="brush: js">17n.toString(); // '17' +66n.toString(2); // '1000010' +254n.toString(16); // 'fe' +-10n.toString(2); // -1010' +-0xffn.toString(2); // '-11111111' +</pre> + +<h3 id="Negative-zero_BigInt">Negative-zero <code>BigInt</code></h3> + +<p>There is no negative-zero <code>BigInt</code> as there are no negative zeros in + integers. <code>-0.0</code> is an IEEE floating-point concept that only appears in the + JavaScript {{jsxref("Number")}} type.</p> + +<pre class="brush: js">(-0n).toString(); // '0' +BigInt(-0).toString(); // '0'</pre> + +<h2 id="Specifications">Specifications</h2> + +{{Specifications}} + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + +<p>{{Compat}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("BigInt.prototype.toLocaleString()")}}</li> + <li>{{jsxref("BigInt.prototype.valueOf()")}}</li> + <li>{{jsxref("Number.prototype.toString()")}}</li> +</ul> |