diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:15 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:41:15 -0500 |
| commit | 4b1a9203c547c019fc5398082ae19a3f3d4c3efe (patch) | |
| tree | d4a40e13ceeb9f85479605110a76e7a4d5f3b56b /files/de/web/javascript/reference/global_objects/math/floor | |
| parent | 33058f2b292b3a581333bdfb21b8f671898c5060 (diff) | |
| download | translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.gz translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.tar.bz2 translated-content-4b1a9203c547c019fc5398082ae19a3f3d4c3efe.zip | |
initial commit
Diffstat (limited to 'files/de/web/javascript/reference/global_objects/math/floor')
| -rw-r--r-- | files/de/web/javascript/reference/global_objects/math/floor/index.html | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/files/de/web/javascript/reference/global_objects/math/floor/index.html b/files/de/web/javascript/reference/global_objects/math/floor/index.html new file mode 100644 index 0000000000..68f8bf86fa --- /dev/null +++ b/files/de/web/javascript/reference/global_objects/math/floor/index.html @@ -0,0 +1,137 @@ +--- +title: Math.floor() +slug: Web/JavaScript/Reference/Global_Objects/Math/floor +tags: + - JavaScript + - Math + - Method + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Math/floor +--- +<div>{{JSRef}}</div> + +<p>Die <strong><code>Math.floor()</code></strong> Funktion gibt den größten Integer zurück, der kleiner oder gleich der gegeben Nummer ist. (Abrunden) </p> + +<div>{{EmbedInteractiveExample("pages/js/math-floor.html")}}</div> + +<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">Math.floor(<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>Eine größte ganze Zahl, die kleiner oder gleich der übergebenen Zahl ist.</p> + +<h2 id="Beschreibung">Beschreibung</h2> + +<p>Weil <code>floor()</code> eine statische Methode von <code>Math</code> ist, wird sie immer als<code> Math.floor() </code>aufgerufen und nicht als eine Methode eines erstellten <code>Math</code> Objektes (<code>Math </code>ist kein Konstruktor).</p> + +<div class="blockIndicator note"> +<p><strong>Hinweis: </strong><code>Math.floor(null)</code> gibt 0, aber nicht {{jsxref("NaN")}}, zurück.</p> +</div> + +<h2 id="Beispiele">Beispiele</h2> + +<h3 id="Einsatz_von_Math.floor">Einsatz von <code>Math.floor()</code></h3> + +<pre class="brush: js">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="Dezimale_Justierung">Dezimale Justierung</h3> + +<pre class="brush: js">/** + * 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' && 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) => decimalAdjust('round', value, exp); +// Decimal floor +const floor10 = (value, exp) => decimalAdjust('floor', value, exp); +// Decimal ceil +const ceil10 = (value, exp) => 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="Spezifikationen">Spezifikationen</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spezifikation</th> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-math.floor', 'Math.floor')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browserkompatibilität">Browserkompatibilität</h2> + + + +<p>{{Compat("javascript.builtins.Math.floor")}}</p> + +<h2 id="Siehe_auch">Siehe auch</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> |
