From cb9e359a51c3249d8f5157db69d43fd413ddeda6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:45:12 +0100 Subject: unslug ca: move --- .../reference/global_objects/math/trunc/index.html | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/math/trunc/index.html (limited to 'files/ca/web/javascript/reference/global_objects/math/trunc') diff --git a/files/ca/web/javascript/reference/global_objects/math/trunc/index.html b/files/ca/web/javascript/reference/global_objects/math/trunc/index.html new file mode 100644 index 0000000000..4f76502d69 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/math/trunc/index.html @@ -0,0 +1,129 @@ +--- +title: Math.trunc() +slug: Web/JavaScript/Referencia/Objectes_globals/Math/trunc +translation_of: Web/JavaScript/Reference/Global_Objects/Math/trunc +--- +
{{JSRef}}
+ +

La funció Math.trunc() retorna la part integral d'un nombre, tot descartant els dígits decimals.

+ +

Sintaxi

+ +
Math.trunc(x)
+ +

Paràmetres

+ +
+
x
+
Un nombre.
+
+ +

Descripció

+ +

Al contrari que altres mètodes de Math : {{jsxref("Math.floor()")}}, {{jsxref("Math.ceil()")}} and {{jsxref("Math.round()")}}, la forma en la que Math.trunc() funciona és molt simple, simplement trunca el punt i els dígits que queden a la dreta, sense importa si l'argument és un nombre positiu o negatiu.

+ +

Així que, si l'argument és un nombre positiu, Math.trunc() és equivalent a Math.floor(), en cas contrari, Math.trunc() és equivalent a Math.ceil().

+ +

Cal destacar que l'argument passat a aquest mètode serà convertit a un nombre de forma implícita.

+ +

Com que trunc() és un mètode estàtic de Math, sempre s'utilitza com Math.trunc() en comptes de com un mètode d'un objecte Math creat (Math no és un constructor).

+ +

Exemples

+ +

Utilitzar Math.trunc()

+ +
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
+
+ +

Polyfill

+ +
Math.trunc = Math.trunc || function(x) {
+  return x < 0 ? Math.ceil(x) : Math.floor(x);
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-math.trunc', 'Math.trunc')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("38")}}{{CompatGeckoDesktop("25")}}{{CompatNo}}{{CompatOpera("25")}}{{CompatSafari("7.1")}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("25")}}{{CompatNo}}{{CompatNo}}8
+
+ +

Vegeu també

+ + -- cgit v1.2.3-54-g00ecf