From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/number/tostring/index.html | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/number/tostring/index.html (limited to 'files/ko/web/javascript/reference/global_objects/number/tostring/index.html') diff --git a/files/ko/web/javascript/reference/global_objects/number/tostring/index.html b/files/ko/web/javascript/reference/global_objects/number/tostring/index.html new file mode 100644 index 0000000000..2c1366ad5b --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/number/tostring/index.html @@ -0,0 +1,112 @@ +--- +title: Number.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Number/toString +tags: + - JavaScript + - Method + - Number + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toString +--- +
{{JSRef}}
+ +

toString() 메서드는 특정한 {{jsxref("Number")}} 객체를 나타내는 문자열을 반환합니다.

+ +

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

+ +

구문

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

매개변수

+ +
+
radix {{optional_inline}}
+
수의 값을 나타내기 위해 사용되기 위한 기준을 정하는 2와 36사이의 정수. (진수를 나타내는 기수의 값.)
+
+ +

반환 값

+ +

{{jsxref("Number")}} 객체를 명시하는 문자열.

+ +

예외

+ +
+
{{jsxref("RangeError")}}
+
만약 toString() 2 36의 사잇 값이 아닌 radix가 주어지면, {{jsxref("RangeError")}} 에러가 발생합니다.
+
+ +

설명

+ +

{{jsxref("Number")}} 객체는 {{jsxref("Object")}} 객체의 toString() 메소드를 오버라이딩하며,  {{jsxref("Object.prototype.toString()")}} 를 상속받지 않습니다. {{jsxref( "Number")}} 객체에서 toString() 메소드는 특정 진수로 객체를 표현한 문자열을 환원합니다.

+ +

toString() 메소드는 메소드의 첫 번째 아규먼트를 파싱하여, 메소드는 특정 기수(radix)를 기준으로 한 진수 값의 문자열을 환원하기 위한 시도를 합니다. 진수를 나타내는 기수 값(radix) 이 10 이상의 값일 때는, 알파벳의 글자는 9보다 큰 수를 나타냅니다. 예를 들면, 16진수(base 16)는, 알파벳 f 까지 사용하여 표현됩니다.

+ +

만약에 radix값 이 지정되지 않으면, 임의로 10진수로 가정하게 됩니다.

+ +

또, numObj가 음수라면, - 부호는 유지됩니다. 이는 기수(radix) 값이 2일 경우에라도 적용됩니다. 리턴된 문자열은 - 부호가 앞에 있는 numObj 의 양의 2진수 표시이지, numObj의 두 개의 조합이 아니기 때문입니다.

+ +

numObj 가 정수가 아니면, 점(.) 부호는 소수 자리와 분리하기 위해 사용됩니다. 

+ +

예제

+ +

toString 사용

+ +
var count = 10;
+
+console.log(count.toString());    // displays '10'
+console.log((17).toString());     // displays '17'
+console.log((17.2).toString());   // displays '17.2'
+
+var x = 6;
+
+console.log(x.toString(2));       // displays '110'
+console.log((254).toString(16));  // displays 'fe'
+
+console.log((-10).toString(2));   // displays '-1010'
+console.log((-0xff).toString(2)); // displays '-11111111'
+
+ +

명세

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}초기 정의. JavaScript 1.1에서 구현됨.
{{SpecName('ES5.1', '#sec-15.7.4.2', 'Number.prototype.tostring')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.prototype.tostring', 'Number.prototype.tostring')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-number.prototype.tostring', 'Number.prototype.tostring')}}{{Spec2('ESDraft')}} 
+ +

브라우저 호환성

+ +

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

+ +

같이 보기

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