aboutsummaryrefslogtreecommitdiff
path: root/files/vi/web/javascript/reference/global_objects/math/floor
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/vi/web/javascript/reference/global_objects/math/floor
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/vi/web/javascript/reference/global_objects/math/floor')
-rw-r--r--files/vi/web/javascript/reference/global_objects/math/floor/index.html132
1 files changed, 132 insertions, 0 deletions
diff --git a/files/vi/web/javascript/reference/global_objects/math/floor/index.html b/files/vi/web/javascript/reference/global_objects/math/floor/index.html
new file mode 100644
index 0000000000..2f660fcf00
--- /dev/null
+++ b/files/vi/web/javascript/reference/global_objects/math/floor/index.html
@@ -0,0 +1,132 @@
+---
+title: Math.floor()
+slug: Web/JavaScript/Reference/Global_Objects/Math/floor
+translation_of: Web/JavaScript/Reference/Global_Objects/Math/floor
+---
+<div>{{JSRef}}</div>
+
+<p>Hàm <strong><code>Math.floor()</code></strong> trả về số nguyên bé hơn hoặc bằng số ban đầu.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/math-floor.html")}}</div>
+
+
+
+<h2 id="Cú_pháp">Cú pháp</h2>
+
+<pre class="syntaxbox notranslate">Math.floor(<var>x</var>)</pre>
+
+<h3 id="Tham_số">Tham số</h3>
+
+<dl>
+ <dt><code>x</code></dt>
+ <dd>Một số.</dd>
+</dl>
+
+<h3 id="Giá_trị_trả_về">Giá trị trả về</h3>
+
+<p>Số nguyên lớn nhất nhỏ hơn hoặc bằng số đã cho.</p>
+
+<h2 id="Mô_tả">Mô tả</h2>
+
+<p>Bởi vì <code>floor()</code> là một phương thức tĩnh của <code>Math</code>, bạn luôn sử dụng <code>Math.floor()</code>, thay vì sử dụng như là một phương thức của đối tượng được tạo ra từ <code>Math</code> (<code>Math</code> không phải là một constructor).</p>
+
+<div class="blockIndicator note">
+<p><strong>Lưu ý: </strong><code>Math.floor(null)</code> trả về 0, không phải {{jsxref("NaN")}}.</p>
+</div>
+
+<h2 id="Ví_dụ">Ví dụ</h2>
+
+<h3 id="Sử_dụng_Math.floor">Sử dụng <code>Math.floor()</code></h3>
+
+<pre class="brush: js notranslate">Math.floor( 45.95); // 45
+Math.floor( 45.05); // 45
+Math.floor( 4 ); // 4
+Math.floor(-45.05); // -46
+Math.floor(-45.95); // -46
+</pre>
+
+<h3 id="Điều_chỉnh_thập_phân">Điều chỉnh thập phân</h3>
+
+<pre class="brush: js notranslate">/**
+ * Decimal adjustment of a number.
+ *
+ * @param {String} type The type of adjustment.
+ * @param {Number} value The number.
+ * @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
+ * @returns {Number} The adjusted value.
+ */
+function decimalAdjust(type, value, exp) {
+ // If the exp is undefined or zero...
+ if (typeof exp === 'undefined' || +exp === 0) {
+ return Math[type](value);
+ }
+ value = +value;
+ exp = +exp;
+ // If the value is not a number or the exp is not an integer...
+ if (isNaN(value) || !(typeof exp === 'number' &amp;&amp; exp % 1 === 0)) {
+ return NaN;
+ }
+ // Shift
+ value = value.toString().split('e');
+ value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
+ // Shift back
+ value = value.toString().split('e');
+ return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
+}
+
+// Decimal round
+const round10 = (value, exp) =&gt; decimalAdjust('round', value, exp);
+// Decimal floor
+const floor10 = (value, exp) =&gt; decimalAdjust('floor', value, exp);
+// Decimal ceil
+const ceil10 = (value, exp) =&gt; decimalAdjust('ceil', value, exp);
+
+// Round
+round10(55.55, -1); // 55.6
+round10(55.549, -1); // 55.5
+round10(55, 1); // 60
+round10(54.9, 1); // 50
+round10(-55.55, -1); // -55.5
+round10(-55.551, -1); // -55.6
+round10(-55, 1); // -50
+round10(-55.1, 1); // -60
+// Floor
+floor10(55.59, -1); // 55.5
+floor10(59, 1); // 50
+floor10(-55.51, -1); // -55.6
+floor10(-51, 1); // -60
+// Ceil
+ceil10(55.51, -1); // 55.6
+ceil10(51, 1); // 60
+ceil10(-55.59, -1); // -55.5
+ceil10(-59, 1); // -50
+</pre>
+
+<h2 id="Quy_cách_kỹ_thuật">Quy cách kỹ thuật</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math.floor', 'Math.floor')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Trình_duyệt_tương_thích">Trình duyệt tương thích</h2>
+
+
+
+<p>{{Compat("javascript.builtins.Math.floor")}}</p>
+
+<h2 id="Xem_thêm">Xem thêm:</h2>
+
+<ul>
+ <li>{{jsxref("Math.abs()")}}</li>
+ <li>{{jsxref("Math.ceil()")}}</li>
+ <li>{{jsxref("Math.round()")}}</li>
+ <li>{{jsxref("Math.sign()")}}</li>
+ <li>{{jsxref("Math.trunc()")}}</li>
+</ul>