mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-28 18:11:29 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div></div>
|
||||
<p><code><strong>Math.trunc()</strong></code> 方法会将数字的小数部分去掉,只保留整数部分。</p>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox">Math.trunc(<em>value</em>)</pre>
|
||||
<pre><code class="language-javascript">Math.trunc(<em>value</em>)</code></pre>
|
||||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||||
<dl>
|
||||
<dt><code>value</code></dt>
|
||||
@@ -15,14 +15,14 @@
|
||||
<p>传入该方法的参数会被隐式转换成数字类型。</p>
|
||||
<p>因为 <code>trunc()</code> 是 <code>Math</code> 对象的静态方法,你必须用 <code>Math.trunc()</code> 来使用,而不是调用你创建的 <code>Math</code> 对象的一个实例方法(<code>Math</code> 没有构造函数)</p>
|
||||
<h2 id="Examples" name="Examples">示例</h2>
|
||||
<pre class="brush:js">Math.trunc(13.37) // 13
|
||||
<pre><code class="language-js">Math.trunc(13.37) // 13
|
||||
Math.trunc(42.84) // 42
|
||||
Math.trunc(0.123) // 0
|
||||
Math.trunc(-0.123) // -0
|
||||
Math.trunc("-1.123") // -1
|
||||
Math.trunc(NaN) // NaN
|
||||
Math.trunc("foo") // NaN
|
||||
Math.trunc() // NaN</pre>
|
||||
Math.trunc() // NaN</code></pre>
|
||||
<h2 id="Polyfill">Polyfill</h2>
|
||||
<pre><code>if (!Math.trunc) {
|
||||
Math.trunc = function(v) {
|
||||
@@ -44,14 +44,14 @@ Math.trunc() // NaN</pre>
|
||||
// null -> 0
|
||||
};
|
||||
}</code>
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>或:</p>
|
||||
<pre><code>if (!Math.trunc) {
|
||||
Math.trunc = function(v) {
|
||||
v = +v;
|
||||
return (v - v % 1) || (!isFinite(v) || v === 0 ? v : v < 0 ? -0 : 0);
|
||||
};
|
||||
}</code></pre>
|
||||
}</code></code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user