aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/errors/bad_radix/index.html
blob: 3ea98bf1ebf3cc338aa632d8294d316d27c2d8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: 'RangeError: radix must be an integer'
slug: Web/JavaScript/Reference/Errors/Bad_radix
translation_of: Web/JavaScript/Reference/Errors/Bad_radix
---
<div>{{jsSidebar("Errors")}}</div>

<h2 id="메시지">메시지</h2>

<pre class="syntaxbox">RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
RangeError: toString() radix argument must be between 2 and 36 (Chrome)
</pre>

<h2 id="에러_형식">에러 형식</h2>

<p>{{jsxref("RangeError")}}</p>

<h2 id="무엇이_잘못되었을까">무엇이 잘못되었을까?</h2>

<p>{{jsxref("Number.prototype.toString()")}} 메소드는 선택적 파라메터인 <code>radix</code>(기수:진수를 지정하는 값)와 함께 사용되어 왔습니다. 이 파라메터는 반드시 수의 값을 나타내는 진법의 2와 36 사이로 지정된 정수(숫자)여야 합니다. </p>

<p>왜 36으로 제한이 되었을까요? <code>radix</code>는 digit(밑기수) 알파벳 글자로 사용되는 10보다는 큽니다. 그렇기 때문에, <code>radix</code>는 라틴 알파벳 26글자를 가졌을 때, 36보다 클 수 없습니다.  </p>

<p>보통 아래의 <code>radix</code> 중 하나를 사용하게 될 것입니다.</p>

<ul>
 <li>2 for <a href="https://en.wikipedia.org/wiki/Binary_number">binary numbers</a> (2진수),</li>
 <li>8 for <a href="https://en.wikipedia.org/wiki/Octal">octal numbers</a> (8진수),</li>
 <li>10 for <a href="https://en.wikipedia.org/wiki/Decimal">decimal numbers</a> (10진수),</li>
 <li>16 for <a href="https://en.wikipedia.org/wiki/Hexadecimal">hexadecimal numbers</a> (16진수).</li>
</ul>

<h2 id="예"></h2>

<h3 id="허용되지_않는_경우">허용되지 않는 경우</h3>

<pre class="brush: js example-bad">(42).toString(0);
(42).toString(1);
(42).toString(37);
(42).toString(150);
//포맷팅하기 위해 string을 이런 식으로 사용할 수는 없습니다. :
(12071989).toString("MM-dd-yyyy");
</pre>

<h3 id="허용된_경우">허용된 경우</h3>

<pre class="brush: js example-good">(42).toString(2);     // "101010" (2진수)
(13).toString(8);     // "15"     (8진수)
(0x42).toString(10);  // "66"     (10진수)
(100000).toString(16) // "186a0"  (16진수)
</pre>

<h2 id="참조">참조</h2>

<ul>
 <li>{{jsxref("Number.prototype.toString()")}}</li>
</ul>