From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../reference/global_objects/math/trunc/index.html | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/math/trunc/index.html (limited to 'files/es/web/javascript/reference/global_objects/math/trunc') diff --git a/files/es/web/javascript/reference/global_objects/math/trunc/index.html b/files/es/web/javascript/reference/global_objects/math/trunc/index.html new file mode 100644 index 0000000000..9efe511927 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/math/trunc/index.html @@ -0,0 +1,144 @@ +--- +title: Math.trunc() +slug: Web/JavaScript/Referencia/Objetos_globales/Math/trunc +tags: + - ECMAScript6 + - JavaScript + - Math + - Método(2) + - Referencia +translation_of: Web/JavaScript/Reference/Global_Objects/Math/trunc +--- +
{{JSRef}}
+ +

La función Math.trunc() devuelve la parte entera de un numero removiendo cualquier dígito decimal (dígitos situados después de la coma).

+ +

Sintaxis.

+ +
Math.trunc(x)
+ +

Parámetros.

+ +
+
x
+
Un número.
+
+ +

Valor de retorno.

+ +

La parte entera del número dado.

+ +

Descripción.

+ +

A diferencia de los otros tres métodos de Math: {{jsxref("Math.floor()")}}, {{jsxref("Math.ceil()")}} y {{jsxref("Math.round()")}}, la forma en que Math.trunc() funciona es muy simple.  trunca (corta) el punto y los dígitos a la derecha de él, sin importar si el argumento es un número positivo o negativo.

+ +

Si el argumento es un número positivo, Math.trunc() es equivalente a Math.floor(); de otra forma Math.trunc() es equivalente a Math.ceil().

+ +

El argumento pasado a este método será convertido a un tipo numérico entero.

+ +

Debido a que trunc() es un método estático de Math, siempre úsalo como Math.trunc(), en lugar de como un método de un objeto Math que hayas creado (Math no es un constructor).

+ +

Ejemplos.

+ +

Usando 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));
+}
+
+ +

Especificaciones.

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

Compatibilidad con navegadores.

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

Vea también.

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