aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/number/toprecision
diff options
context:
space:
mode:
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects/number/toprecision')
-rw-r--r--files/ko/web/javascript/reference/global_objects/number/toprecision/index.html110
1 files changed, 110 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/global_objects/number/toprecision/index.html b/files/ko/web/javascript/reference/global_objects/number/toprecision/index.html
new file mode 100644
index 0000000000..83cf3017e3
--- /dev/null
+++ b/files/ko/web/javascript/reference/global_objects/number/toprecision/index.html
@@ -0,0 +1,110 @@
+---
+title: Number.prototype.toPrecision()
+slug: Web/JavaScript/Reference/Global_Objects/Number/toPrecision
+tags:
+ - JavaScript
+ - Method
+ - Number
+ - Prototype
+ - toPrecision
+translation_of: Web/JavaScript/Reference/Global_Objects/Number/toPrecision
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>toPrecision()</code></strong> 메서드는 {{jsxref("Number")}} 객체를 지정된 정밀도로 나타내는 문자열을 반환한다.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/number-toprecision.html")}}</div>
+
+<h2 id="문법">문법</h2>
+
+<pre class="syntaxbox"><var>numObj</var>.toPrecision([<var>precision</var>])</pre>
+
+<h3 id="파라미터">파라미터</h3>
+
+<dl>
+ <dt><code>precision</code></dt>
+ <dd>선택적 파라미터. 유효 자릿수를 지정하는 정수.</dd>
+</dl>
+
+<h3 id="반환_값">반환 값</h3>
+
+<p>고정 소수점 또는 지수 표기법의 {{jsxref("Number")}} 객체를 정밀 유효 숫자로 반올림 한 문자열입니다. <code>toPrecision()</code>에도 적용되는 {{jsxref("Number.prototype.toFixed()")}} 메서드에 대한 설명에서 반올림에 대한 설명을 참조하세요.</p>
+
+<p><code>precision(정밀도)</code> 인수가 생략되면 {{jsxref("Number.prototype.toString()")}}처럼 작동합니다. <code>precision(정밀도)</code> 인수가 정수가 아닌 값이면 가장 가까운 정수로 반올림됩니다.</p>
+
+<p> </p>
+
+<h3 id="예외">예외</h3>
+
+<dl>
+ <dt>{{jsxref("Global_Objects/RangeError", "RangeError")}}</dt>
+ <dd><code>precision(정밀도)</code>가 1에서 100 사이가 아닌 경우 {{jsxref("RangeError")}}가 발생합니다. 구현은 더 큰 값과 더 작은 값을 지원할 수 있습니다. ECMA-262는 최대 21 자리의 정밀도 만을 요구합니다.</dd>
+</dl>
+
+<h2 id="예제">예제</h2>
+
+<h3 id="toPrecision_사용"><code>toPrecision</code> 사용</h3>
+
+<pre class="brush: js">var numObj = 5.123456;
+
+console.log(numObj.toPrecision()); // logs '5.123456'
+console.log(numObj.toPrecision(5)); // logs '5.1235'
+console.log(numObj.toPrecision(2)); // logs '5.1'
+console.log(numObj.toPrecision(1)); // logs '5'
+
+numObj = 0.000123
+
+console.log(numObj.toPrecision()); // logs '0.000123'
+console.log(numObj.toPrecision(5)); // logs '0.00012300'
+console.log(numObj.toPrecision(2)); // logs '0.00012'
+console.log(numObj.toPrecision(1)); // logs '0.0001'
+
+// 일부 상황에서는 지수 표기법이 반환 될 수 있습니다
+console.log((1234.5).toPrecision(2)); // logs '1.2e+3'
+</pre>
+
+<h2 id="명세">명세</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.5.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.7.4.7', 'Number.prototype.toPrecision')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-number.prototype.toprecision', 'Number.prototype.toPrecision')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-number.prototype.toprecision', 'Number.prototype.toPrecision')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="브라우저_호환성">브라우저 호환성</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.Number.toPrecision")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Number.prototype.toFixed()")}}</li>
+ <li>{{jsxref("Number.prototype.toExponential()")}}</li>
+ <li>{{jsxref("Number.prototype.toString()")}}</li>
+</ul>