aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/math/trunc/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/de/web/javascript/reference/global_objects/math/trunc/index.html')
-rw-r--r--files/de/web/javascript/reference/global_objects/math/trunc/index.html125
1 files changed, 125 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/global_objects/math/trunc/index.html b/files/de/web/javascript/reference/global_objects/math/trunc/index.html
new file mode 100644
index 0000000000..43aa34b2d7
--- /dev/null
+++ b/files/de/web/javascript/reference/global_objects/math/trunc/index.html
@@ -0,0 +1,125 @@
+---
+title: Math.trunc()
+slug: Web/JavaScript/Reference/Global_Objects/Math/trunc
+tags:
+ - ECMAScript 2015
+ - JavaScript
+ - Math
+ - Method
+ - Reference
+translation_of: Web/JavaScript/Reference/Global_Objects/Math/trunc
+---
+<div>{{JSRef}}</div>
+
+<p>Die <strong><code>Math.trunc()</code></strong> Funktion gibt den ganzzahligen Teil einer Zahl zurück, indem alle Nachkommastellen entfernt werden.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/math-trunc.html")}}</div>
+
+
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox">Math.trunc(<var>x</var>)</pre>
+
+<h3 id="Parameter">Parameter</h3>
+
+<dl>
+ <dt><code>x</code></dt>
+ <dd>Eine Zahl.</dd>
+</dl>
+
+<h3 id="Rückgabewert">Rückgabewert</h3>
+
+<p>Den ganzzahligen Teil der übergebenen Zahl.</p>
+
+<h2 id="Beschreibung">Beschreibung</h2>
+
+<p>Im Gegensatz zu den drei <code>Math</code> Funktionen {{jsxref("Math.floor()")}}, {{jsxref("Math.ceil()")}} und {{jsxref("Math.round()")}} arbeitet <code>Math.trunc()</code> sehr einfach. Sie entfernt den Punkt und die Ziffern rechts davon, ohne zu beachten, ob es sich um eine positive oder negative Nummer handelt.</p>
+
+<p>Beim übergeben eines Parameters wird dieser implizit in einen Nummern-Typ konvertiert.</p>
+
+<p>Weil <code>trunc()</code> eine statische Funktion von <code>Math</code> ist, wird es immer als <code>Math.trunc()</code> eingesetzt<code>,</code> jedoch nicht als Methode eines erzeugten <code>Math</code> Objektes (<code>Math</code> ist kein Konstruktor).</p>
+
+<h2 id="Beispiele">Beispiele</h2>
+
+<h3 id="Einsatz_von_Math.trunc">Einsatz von <code>Math.trunc()</code></h3>
+
+<pre class="brush: 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>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<pre class="brush: js">if(!Math.trunc) {
+ Math.trunc = function(v) {
+ v = +v;
+ if(!isFinite(v)) return v;
+
+ return (v - v % 1) || (v &lt; 0 ? -0 : v === 0 ? v : 0);
+
+ // returns:
+ // 0 -&gt; 0
+ // -0 -&gt; -0
+ // 0.2 -&gt; 0
+ // -0.2 -&gt; -0
+ // 0.7 -&gt; 0
+ // -0.7 -&gt; -0
+ // Infinity -&gt; Infinity
+ // -Infinity -&gt; -Infinity
+ // NaN -&gt; NaN
+ // null -&gt; 0
+ };
+}</pre>
+
+<p>oder:</p>
+
+<pre class="brush: js line-numbers language-js">if(!Math.trunc) {
+ Math.trunc = function(v) {
+ return v &lt; 0 ? Math.ceil(v) : Math.floor(v);
+ }
+}
+</pre>
+
+<h2 id="Spezifikationen">Spezifikationen</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spezifikation</th>
+ <th scope="col">Status</th>
+ <th scope="col">Kommentar</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-math.trunc', 'Math.trunc')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>Initiale Definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-math.trunc', 'Math.trunc')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browserkompatibilität">Browserkompatibilität</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.Math.trunc")}}</p>
+
+<h2 id="Siehe_auch">Siehe auch</h2>
+
+<ul>
+ <li>{{jsxref("Math.abs()")}}</li>
+ <li>{{jsxref("Math.ceil()")}}</li>
+ <li>{{jsxref("Math.floor()")}}</li>
+ <li>{{jsxref("Math.round()")}}</li>
+ <li>{{jsxref("Math.sign()")}}</li>
+</ul>