diff options
author | Florian Dieminger <me@fiji-flo.de> | 2021-02-11 18:20:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 18:20:58 +0100 |
commit | 2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb (patch) | |
tree | 5e640d40fd69dc380b04e01de981a345e0141ffa /files/es/web/javascript/reference/global_objects/number | |
parent | 6aa6274d2ad3e22e7f5e69b1d7531a5eaeaf5666 (diff) | |
parent | 8a5554c6fae83e92b10c8dbe5b82108cb44fad6c (diff) | |
download | translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.tar.gz translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.tar.bz2 translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.zip |
Merge pull request #53 from fiji-flo/unslugging-es
Unslugging es
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/number')
18 files changed, 1935 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/global_objects/number/index.html b/files/es/web/javascript/reference/global_objects/number/index.html new file mode 100644 index 0000000000..9e14baa221 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/index.html @@ -0,0 +1,182 @@ +--- +title: Number +slug: Web/JavaScript/Reference/Global_Objects/Number +tags: + - JavaScript + - Number + - Referencia + - Referência(2) +translation_of: Web/JavaScript/Reference/Global_Objects/Number +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number +--- +<div>{{JSRef}}</div> + +<p><strong><code>Number</code></strong> es un objeto primitivo envolvente que permite representar y manipular valores numéricos cómo 37 o -9.25. El constructor Number contiene constantes y métodos para trabajar con números. Valores de otro tipo pueden ser convertidos a números usando la función Number().</p> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox notranslate">new Number(<em>value</em>); +var <em>a</em> = new Number('123'); // a === 123 es false +var <em>b</em> = Number('123'); // b === 123 es true +<em>a</em> instanceof Number; // es true +<em>b</em> instanceof Number; // es false</pre> + +<h3 id="Parámetros" name="Parámetros">Parámetros</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor numérico de un objeto que está siendo creado.</dd> +</dl> + +<h2 id="Descripci.C3.B3n" name="Descripci.C3.B3n">Descripción</h2> + +<p>Los principales usos del objeto <code>Number(valor)</code> son convertir un string u otro valor a uno de tipo numérico; si el argumento no puede ser convertido a un número, devuelve {{jsxref("NaN")}}.</p> + +<h3 id="Literal_syntax">Literal syntax</h3> + +<pre class="notranslate">123 // one-hundred twenty-three +123.0 // same +123 === 123.0 // true</pre> + +<h3 id="Function_syntax">Function syntax</h3> + +<pre class="notranslate">Number('123') // retorna el número 123 +Number('123') === 123 // retorna true + +Number("unicorn") // NaN +Number(undefined) // NaN</pre> + +<h2 id="Constructor">Constructor</h2> + +<dl> + <dt><a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number"><code>Number()</code></a></dt> + <dd>Crea un nuevo valor Numérico ( <code>Number</code> value).</dd> +</dl> + +<h2 id="Propiedades">Propiedades</h2> + +<dl> + <dt>{{jsxref("Number.EPSILON")}}</dt> + <dd>El intervalo más pequeño entre dos números representables</dd> + <dt>{{jsxref("Number.MAX_SAFE_INTEGER")}}</dt> + <dd>El número máximo representable en JavaScript (<code>2<sup>53</sup> - 1</code>).</dd> + <dt>{{jsxref("Number.MAX_VALUE")}}</dt> + <dd>El número más grande representable.</dd> + <dt>{{jsxref("Number.MIN_SAFE_INTEGER")}}</dt> + <dd>El número mínimo representable en JavaScript (<code>-(2<sup>53</sup> - 1)</code>).</dd> + <dt>{{jsxref("Number.MIN_VALUE")}}</dt> + <dd>El número más pequeño representable - que es el número positivo más cercano a cero (sin llegar a ser cero)-.</dd> + <dt>{{jsxref("Number.NaN")}}</dt> + <dd>Valor especial "no es número" NaN.</dd> + <dt>{{jsxref("Number.NEGATIVE_INFINITY")}}</dt> + <dd>Valor especial para representar infinitos negativos; retorno de un desborde de pila overflow.</dd> + <dt>{{jsxref("Number.POSITIVE_INFINITY")}}</dt> + <dd>Valor especial para representar infinitos positivos; retorno de un desborde de pila overflow.</dd> + <dt>{{jsxref("Number.prototype")}}</dt> + <dd>Permite la adición de propiedades a un objeto <code>Number</code>.</dd> +</dl> + +<h2 id="Métodos">Métodos</h2> + +<dl> + <dt>{{jsxref("Number.isNaN()")}}</dt> + <dd>Determina si el valor es NaN.</dd> + <dt>{{jsxref("Number.isFinite()")}}</dt> + <dd>Determina si el valor es un numero infinito.</dd> + <dt>{{jsxref("Number.isInteger()")}}</dt> + <dd>Determina si un numero es entero.</dd> + <dt>{{jsxref("Number.isSafeInteger()")}}</dt> + <dd>Determine si el valor pasado es un entero seguro (número entre <code>-(2<sup>53</sup> - 1)</code> y <code>2<sup>53</sup> - 1</code>).</dd> + <dt><s class="obsoleteElement">{{jsxref("Number.toInteger()")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Se usa para evaluar el valor pasado y convertirlo en un entero (or {{jsxref("Global_Objects/Infinity", "Infinity")}}), pero ha sido eliminado.</s></dd> + <dt>{{jsxref("Number.parseFloat()")}}</dt> + <dd>El valor es el mismo que {{jsxref ("parseFloat", "parseFloat ()")}} del objeto global.</dd> + <dt>{{jsxref("Number.parseInt()")}}</dt> + <dd>El valor es el mismo que {{jsxref("parseInt", "parseInt()")}} del objeto global.</dd> +</dl> + +<h2 id="Instancias_Number">Instancias <code>Number</code></h2> + +<p>Todas las instancias <code>Number</code> heredan de {{jsxref("Number.prototype")}}. El objeto prototipo del constructor de <code>Number</code> puede modificarse para aceptar a todas las instancias de <code>Number</code>.</p> + +<h3 id="Métodos_2">Métodos</h3> + +<dl> + <dt>{{jsxref("Number.prototype.toExponential()" ,"Number.prototype.toExponential(<var>fractionDigits</var>)")}}</dt> + <dd>Devuelve una cadena que representa el número en notación exponencial.</dd> +</dl> + +<dl> + <dt>{{jsxref("Number.prototype.toFixed()", "Number.prototype.toFixed(<var>digits</var>)")}}</dt> + <dd>Devuelve una cadena que representa el número en notación de punto fijo.</dd> + <dt>{{jsxref("Number.prototype.toLocaleString()", "Number.prototype.toLocaleString([<var>locales</var> [, <var>options</var>]])")}}</dt> + <dd>Devuelve una cadena con una representación sensible al idioma de este número. Invalida el método {{jsxref ("Object.prototype.toLocaleString ()")}}.</dd> +</dl> + +<h2 id="Ejemplos" name="Ejemplos">Ejemplos</h2> + +<h3 id="Ejemplo_Utilizando_el_objeto_Number_para_asignar_valores_a_variables_num.C3.A9ricas" name="Ejemplo:_Utilizando_el_objeto_Number_para_asignar_valores_a_variables_num.C3.A9ricas">Ejemplo: Utilizando el objeto <code>Number</code> para asignar valores a variables numéricas</h3> + +<p>El siguiente ejemplo utiliza las propiedades del objeto <code>Number</code> para asignar valores a varias variables numéricas:</p> + +<pre class="brush: js notranslate">const MásgrandeNum = Number.MAX_VALUE; +const MáspequeNum = Number.MIN_VALUE; +const infinitoNum = Number.POSITIVE_INFINITY; +const notInfinitoNum = Number.NEGATIVE_INFINITY; +const noEsNum = Number.NaN; +</pre> + +<h3 id="Ejemplo_Utilizando_el_objeto_Number_para_modificar_todos_los_objetos__Number" name="Ejemplo:_Utilizando_el_objeto_Number_para_modificar_todos_los_objetos__Number">Intervalo de enteros para Number</h3> + +<p>El siguiente ejemplo muestra los valores máximos y minimos que pueden ser representados mediante el objeto Number: </p> + +<p>Cuando se analizan datos que se han serializado en JSON, se puede esperar que los valores enteros que se encuentran fuera de este rango se corrompan cuando el analizador JSON los coacciona al tipo Number.</p> + +<p>Una posible solución es usar {{jsxref ("String")}} en su lugar.</p> + +<p>Los números más grandes se pueden representar usando el tipo {{jsxref ("BigInt")}}.</p> + +<pre class="notranslate">const biggestInt = Number.MAX_SAFE_INTEGER // (<code>2<sup>53</sup> - 1</code>) => 9007199254740991 +const smallestInt = Number.MIN_SAFE_INTEGER // -(<code>2<sup>53</sup> - 1</code>) => -9007199254740991</pre> + +<h3 id="Ejemplo_Utilizando_el_objeto_Number_para_modificar_todos_los_objetos__Number" name="Ejemplo:_Utilizando_el_objeto_Number_para_modificar_todos_los_objetos__Number">Ejemplo: Utilizando el objeto <code>Number</code> para modificar todos los objetos <code>Number</code></h3> + +<p>El siguiente ejemplo crea un objeto Number, miNúmero, luego añade la propiedad descripción a todos los objetos Number. Luego el valor es asignado a la propiedad descripción del objeto miNúmero.</p> + +<pre class="brush: js notranslate">miNúmero = new Number(65); +Number.prototype.descripción = null; +miNúmero.descripción = "velocidad del viento"; +</pre> + +<h3 id="Utilizando_el_objecto_Number_para_transformar_un_objeto_Date">Utilizando el objecto <code>Number</code> para transformar un objeto <code>Date</code> </h3> + +<p>El siguiente ejemplo convierte el objeto {{jsxref ("Date")}} a un valor numérico usando <code>Number</code> como función:</p> + +<pre class="notranslate"><code>var d = new Date('December 17, 1995 03:24:00'); +console.log(Number(d));</code></pre> + +<p>Esto muestra "819199440000".</p> + +<h3 id="Convierte_cadenas_numéricas_a_números">Convierte cadenas numéricas a números</h3> + +<pre class="notranslate"><code>Number('123') // 123 +Number('12.3') // 12.3 +Number('123e-1') // 12.3 +Number('') // 0 +Number('0x11') // 17 +Number('0b11') // 3 +Number('0o11') // 9 +Number('foo') // NaN +Number('100a') // NaN</code></pre> + +<pre dir="rtl">Number('-Infinity') //-Infinity</pre> + + + +<h3 id="Vea_También">Vea También</h3> + +<ul> + <li>{{jsxref("Global_Objects/NaN", "NaN")}}</li> + <li>{{jsxref("Global_Objects/Math", "Math")}}</li> + <li>{{jsxref("Arithmetic operators")}} </li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/isfinite/index.html b/files/es/web/javascript/reference/global_objects/number/isfinite/index.html new file mode 100644 index 0000000000..7435a50179 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/isfinite/index.html @@ -0,0 +1,89 @@ +--- +title: Number.isFinite() +slug: Web/JavaScript/Reference/Global_Objects/Number/isFinite +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isFinite +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/isFinite +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>Number.isFinite()</code></strong> determina si el valor pasado es un número finito.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-isfinite.html")}}</div> + + + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">Number.isFinite(valor)</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor cuya finitud será probada.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>Un {{jsxref("Boolean")}} indicando si el valor dado es finito o no.</p> + +<h2 id="Description">Description</h2> + +<p>En comparación con la funcion global {{jsxref("isFinite", "isFinite()")}} , este método no convierte el parámetro forzádamente a un número. Esto significa que solo valores de tipo númerico, que también son finitos, retornan <code>true</code>.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<pre class="brush: js">Number.isFinite(Infinity); // false +Number.isFinite(NaN); // false +Number.isFinite(-Infinity); // false + +Number.isFinite(0); // true +Number.isFinite(2e64); // true + +Number.isFinite('0'); // false, retornaría true con la función + // global isFinite('0') +Number.isFinite(null); // false, retornaría true con la función + // global isFinite(null) +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">Number.isFinite = Number.isFinite || function(value) { + return typeof value === 'number' && isFinite(value); +} +</pre> + +<h2 id="Specificaciones">Specificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isfinite', 'Number.isInteger')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.isfinite', 'Number.isInteger')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegador">Compatibilidad de navegador</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.Number.isFinite")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>El objeto {{jsxref("Number")}} al que pertenece esta función.</li> + <li>La función global {{jsxref("isFinite")}}.</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/isinteger/index.html b/files/es/web/javascript/reference/global_objects/number/isinteger/index.html new file mode 100644 index 0000000000..f21e26ed84 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/isinteger/index.html @@ -0,0 +1,95 @@ +--- +title: Number.isInteger() +slug: Web/JavaScript/Reference/Global_Objects/Number/isInteger +tags: + - JavaScript + - Number + - Referencia + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isInteger +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/isInteger +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>Number.isInteger()</code></strong> determina si el valor pasado es de tipo entero.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-isinteger.html")}}</div> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><code>Number.isInteger(valor)</code></pre> + +<h3 id="Parámetros" name="Parámetros">Parámetros</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor a ser probado si es un entero.</dd> +</dl> + +<h3 id="Valor_devuelto">Valor devuelto</h3> + +<p>Un {{jsxref("Boolean")}} indicando si el valor dado es un entero o no.</p> + +<h2 id="Descripción">Descripción </h2> + +<p>Si el valor seleccionado es un entero, devuelve <code>true</code>, de lo contrario <code>false</code>. Si el valor es {{jsxref("NaN")}} o infinito, devuelve <code>false</code>.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<pre class="brush: js">Number.isInteger(0); // true +Number.isInteger(1); // true +Number.isInteger(-100000); // true +Number.isInteger(99999999999999999999999); // true + +Number.isInteger(0.1); // false +Number.isInteger(Math.PI); // false + +Number.isInteger(NaN); // false +Number.isInteger(Infinity); // false +Number.isInteger(-Infinity); // false +Number.isInteger('10'); // false +Number.isInteger(true); // false +Number.isInteger(false); // false +Number.isInteger([1]); // false +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">Number.isInteger = Number.isInteger || function(value) { + return typeof value === 'number' && + isFinite(value) && + Math.floor(value) === value; +}; +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isinteger', 'Number.isInteger')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.isinteger', 'Number.isInteger')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatitibilidad_con_navegadores">Compatitibilidad con navegadores</h2> + +<p>{{Compat("javascript.builtins.Number.isInteger")}}</p> + +<h2 id="Ver también" name="Ver también">Ver también</h2> + +<ul> + <li>El objeto {{jsxref("Number")}} al que pertenece.</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/isnan/index.html b/files/es/web/javascript/reference/global_objects/number/isnan/index.html new file mode 100644 index 0000000000..5d638d528f --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/isnan/index.html @@ -0,0 +1,141 @@ +--- +title: Number.isNaN() +slug: Web/JavaScript/Reference/Global_Objects/Number/isNaN +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isNaN +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/isNaN +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>Number.isNaN()</code></strong> determina si el valor pasado es {{jsxref("NaN")}}. Versión más robusta de la función global {{jsxref("isNaN", "isNaN()")}}.</p> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox notranslate"><code>Number.isNaN(v<var>alue</var>)</code></pre> + +<h3 id="Parámetros">Parámetros</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor para ser evaluado por {{jsxref("NaN")}}.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<p>Debido a los dos operadores de igualdad, {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}} y {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}, evaluando a <code>false</code> cuando al comprobar si {{jsxref("NaN")}} <em>is</em> {{jsxref("NaN")}}, la función <code>Number.isNaN()</code> se ha convertido en necesaria. Esta situación es diferente a las otras comparaciones de valor en JavaScript.</p> + +<p>En comparación a la función global {{jsxref("isNaN", "isNaN()")}}, <code>Number.isNaN()</code> no sufre el problema de forzar la conversión del parámetro a un número. Esto significa que ahora es seguro pasar valores que normalmente se convertirían a {{jsxref("NaN")}}, pero no son del mismo valor que {{jsxref("NaN")}}. Esto también significa que solo los valores de tipo número, que también son {{jsxref("NaN")}}, retornan <code>true</code>.</p> + +<h2 id="Examples">Examples</h2> + +<pre class="brush: js notranslate">Number.isNaN(NaN); // true +Number.isNaN(Number.NaN); // true +Number.isNaN(0 / 0) // true + +// e.g. estos hubiesen sido true con la función global isNaN() +Number.isNaN("NaN"); // false +Number.isNaN(undefined); // false +Number.isNaN({}); // false +Number.isNaN("blabla"); // false + +// Todos retornan false +Number.isNaN(true); +Number.isNaN(null); +Number.isNaN(37); +Number.isNaN("37"); +Number.isNaN("37.37"); +Number.isNaN(""); +Number.isNaN(" "); +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js notranslate">Number.isNaN = Number.isNaN || function(value) { + return typeof value === "number" && isNaN(value); +} + +// O +Number.isNaN = Number.isNaN || function(value) { + return value !== value; +} +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isnan', 'Number.isnan')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.isnan', 'Number.isnan')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegador">Compatibilidad de navegador</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome("25")}}</td> + <td>{{CompatGeckoDesktop("15")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>9</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("15")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>9</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number")}}</li> + <li>{{jsxref("isNaN", "isNaN()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/issafeinteger/index.html b/files/es/web/javascript/reference/global_objects/number/issafeinteger/index.html new file mode 100644 index 0000000000..e7e9fb7855 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/issafeinteger/index.html @@ -0,0 +1,100 @@ +--- +title: Number.isSafeInteger() +slug: Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger +tags: + - ECMAScript6 + - JavaScript + - Number + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/isSafeInteger +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>Number.isSafeInteger()</code></strong> determina si el valor provisto es un número que es un entero seguro.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-issafeinteger.html")}}</div> + + + +<p>Un entero seguro es un entero que</p> + +<ul> + <li>puede ser exactamente representado como un número IEEE-754 de doble presición, y</li> + <li>su representación IEEE-754 no puede ser el resultado de redondear cualquier otro entero para adaptarse a la representación de IEEE-754.</li> +</ul> + +<p>Por ejemplo, <code>2<sup>53</sup> - 1</code> es un entero seguro: puede ser exactamente representado y ningún otro entero puede ser redondeado a él bajo cualquier modo de redondeo de IEEE-754. En contraste, <code>2<sup>53</sup></code> <em>no</em> es un entero seguro, puede ser exactamente representado en IEEE-754, pero el entero <code>2<sup>53</sup> + 1</code> no puede ser directamente representado en IEEE-754 pero en su lugar, redondea a <code>2<sup>53</sup></code> bajo los modos de redondeo <em>redondeo-al-más-cercano</em> y <em>redondeo-a-cero</em>. Los enteros seguros consisten en todos los enteros desde <code>-(2<sup>53</sup> - 1)</code> inclusivo, hasta <code>2<sup>53</sup> - 1</code> inclusivo (± <code>9007199254740991</code> o ± 9,007,199,254,740,991). </p> + +<p>Manejar valores más grandes o más pequeños que ~9 cuatrillones con presición completa requiere usar una <a href="https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic">biblioteca de artimética de presición arbitraria</a>. Ver <a href="http://floating-point-gui.de/">Lo que todo programador necesita saber sobre aritmética de punto flotante</a> para más información sobre representaciones de punto flotante de los números.</p> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><code>Number.isSafeInteger(<em>valorDePrueba</em>)</code> +</pre> + +<h3 id="Parámetros">Parámetros</h3> + +<dl> + <dt><code><em>valorDePrueba</em></code></dt> + <dd>El valor a probar si es un entero seguro.</dd> +</dl> + +<h3 id="Valor_de_retorno">Valor de retorno</h3> + +<p>Un {{jsxref("Boolean")}} que indica si el valor dado es un número que es entero seguro.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<pre class="brush: js">Number.isSafeInteger(3); // true +Number.isSafeInteger(Math.pow(2, 53)); // false +Number.isSafeInteger(Math.pow(2, 53) - 1); // true +Number.isSafeInteger(NaN); // false +Number.isSafeInteger(Infinity); // false +Number.isSafeInteger('3'); // false +Number.isSafeInteger(3.1); // false +Number.isSafeInteger(3.0); // true +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">Number.isSafeInteger = Number.isSafeInteger || function (value) { + return Number.isInteger(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER; +}; +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estatus</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-number.issafeinteger', 'Number.isSafeInteger')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.issafeinteger', 'Number.isSafeInteger')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</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.Number.isSafeInteger")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>El objeto {{jsxref("Number")}} al que pertenece.</li> + <li>{{jsxref("Number.MIN_SAFE_INTEGER")}}</li> + <li>{{jsxref("Number.MAX_SAFE_INTEGER")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/max_safe_integer/index.html b/files/es/web/javascript/reference/global_objects/number/max_safe_integer/index.html new file mode 100644 index 0000000000..9dd417e292 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/max_safe_integer/index.html @@ -0,0 +1,69 @@ +--- +title: Number.MAX_SAFE_INTEGER +slug: Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER +tags: + - ECMAScript 2015 + - JavaScript + - Number + - Property +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/MAX_SAFE_INTEGER +--- +<div>{{JSRef}}</div> + +<p>La constante <strong><code>Number.MAX_SAFE_INTEGER</code></strong> es el número mas grande 'seguro' en JavaScript (<code>2<sup>53</sup> - 1</code>).</p> + +<div>{{EmbedInteractiveExample("pages/js/number-maxsafeinteger.html")}}</div> + +<p class="hidden">La fuente de este ejemplo interactivo está almacenada en GitHub. Si quieres contribuir al proyecto de ejmplos interactivos, por favor clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> y envíanos un 'pull request'.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Descripción">Descripción</h2> + +<p>La constante <code>MAX_SAFE_INTEGER</code> tiene un valor de <code>9007199254740991</code> (9,007,199,254,740,991 o ~9 mil billones). El razonamiento detrás de ese número es que JavaScript usa <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format">números flotantes de doble precisión</a> tal como está especfificado en <a href="http://en.wikipedia.org/wiki/IEEE_floating_point">IEEE 754</a> por lo que puedes representar números de forma segura entre <code>-(2<sup>53</sup> - 1)</code> y <code>2<sup>53</sup> - 1</code>.</p> + +<p>Seguro, en este contexto, se refiere a la habilidad de representar enteros de forma exacta y compararlos de forma correcta. Por ejemplo, <code>Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2</code> evaluará como 'verdadero', lo cual es matemáticamente incorrecto. Ver {{jsxref("Number.isSafeInteger()")}} para más información.</p> + +<p>Debido a que <code>MAX_SAFE_INTEGER</code> es una propiedad estática de {{jsxref("Number")}}, siempre se usa como <code>Number.MAX_SAFE_INTEGER</code>, en lugar de como una propiedad de un objeto {{jsxref("Number")}} que hayas creado.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<pre class="brush: js">Number.MAX_SAFE_INTEGER // 9007199254740991 +Math.pow(2, 53) - 1 // 9007199254740991 +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estatus</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-number.max_safe_integer', 'Number.MAX_SAFE_INTEGER')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.max_safe_integer', 'Number.MAX_SAFE_INTEGER')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2> + +<p class="hidden">La tabla de compatibilidad en esta página está generada con base en información estructurada. Si quieres contribuir a dicha información, por favor revisa <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos un 'pull request'.</p> + +<p>{{Compat("javascript.builtins.Number.MAX_SAFE_INTEGER")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number.MIN_SAFE_INTEGER")}}</li> + <li>{{jsxref("Number.isSafeInteger()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/max_value/index.html b/files/es/web/javascript/reference/global_objects/number/max_value/index.html new file mode 100644 index 0000000000..814beaac14 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/max_value/index.html @@ -0,0 +1,132 @@ +--- +title: Number.MAX_VALUE +slug: Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/MAX_VALUE +--- +<div>{{JSRef}}</div> + +<div>La propiedad <strong><code>Number.MAX_VALUE</code></strong><code> </code>representa el valor numérico positivo máximo representable en JavaScript.</div> + +<div> </div> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Descripción">Descripción</h2> + +<p>La propiedad <code>MAX_VALUE</code> tiene un valor aproximado a <code>1.79E+308</code>. Si el valor es mayor será representado como <em><code>Infinity</code></em>.</p> + +<p>Dado que <code>MAX_VALUE</code> es una propiedad estática de {{jsxref("Number")}}, siempre ha de usarse como <code>Number.MAX_VALUE</code>, y no como propiedad del objeto que has creado.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Usando_MAX_VALUE">Usando <code>MAX_VALUE</code></h3> + +<p>La función <em>verificarValorMaximo </em>recibe un número como parámetro que se compara con <em>Number.MAX_VALUE. </em>Si el número es menor se imprime por consola <em>"El número no es infinito"</em>, de ser mayor <em>"El número es infinito"</em>.</p> + +<pre class="brush: js">var numero1 = 1.79E+307; +var numero2 = 1.79E+310; + +function verificarValorMaximo(num){ + + if (num <= Number.MAX_VALUE) { + console.log("El número no es infinito"); + } else { + console.log("El número es infinito"); + } + +} + +verificarValorMaximo(numero1); // El número no es infinito +verificarValorMaximo(numero2); // El número es infinito +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.3.2', 'Number.MAX_VALUE')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.max_value', 'Number.MAX_VALUE')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.max_value', 'Number.MAX_VALUE')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad">Compatibilidad</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number.MIN_VALUE")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/min_value/index.html b/files/es/web/javascript/reference/global_objects/number/min_value/index.html new file mode 100644 index 0000000000..3b0b515b63 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/min_value/index.html @@ -0,0 +1,122 @@ +--- +title: Number.MIN_VALUE +slug: Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/MIN_VALUE +--- +<div>{{JSRef}}</div> + +<p>La propiedad <code><strong>Number.MIN_VALUE</strong></code> representa el menor valor positivo numérico representable en JavaScript.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Descripción">Descripción</h2> + +<p>La propiedad <code>MIN_VALUE </code>es el número más cercano a 0, no el más negativo, que JavaScript puede representar.</p> + +<p><code>MIN_VALUE </code>tiene un valor aproximado de <code>5e-324</code>. Los valores menores que <code>MIN_VALUE </code>(“subdesbordamiento de valores”) son convertidos a 0.</p> + +<p>Ya que <code>MIN_VALUE </code>es una propiedad estática de {{jsxref("Number")}}, debes utilizarla como <code>Number.MIN_VALUE</code>, más que como una propiedad del objeto {{jsxref("Number")}} que has creado.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Usando_MIN_VALUE">Usando <code>MIN_VALUE</code></h3> + +<p>El siguiente código divide dos valores numéricos. Si el resultado es mayor o igual a <code>MIN_VALUE</code>, se ejecuta la función <code>func1</code>, si no, se ejecuta la función <code>func2</code>.</p> + +<pre class="brush: js">if (num1 / num2 >= Number.MIN_VALUE) { + func1(); +} else { + func2(); +} +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.3.3', 'Number.MIN_VALUE')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.min_value', 'Number.MIN_VALUE')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.min_value', 'Number.MIN_VALUE')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegador">Compatibilidad de navegador</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number.MAX_VALUE")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/nan/index.html b/files/es/web/javascript/reference/global_objects/number/nan/index.html new file mode 100644 index 0000000000..dd71aa97df --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/nan/index.html @@ -0,0 +1,60 @@ +--- +title: Number.NaN +slug: Web/JavaScript/Reference/Global_Objects/Number/NaN +tags: + - JavaScript + - Número + - Propiedad +translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/NaN +--- +<div>{{JSRef}}</div> + +<p>La propiedad <strong><code>Number.NaN</code></strong> representa Not-A-Number (No es numero). Equivalente de {{jsxref("NaN")}}.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-nan.html")}}</div> + +<p>No tienes que crear un objeto {{jsxref("Number")}} para acceder a esta propiedad estática (usa <code>Number.NaN</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Chequea_si_los_valores_son_numericos">Chequea si los valores son numericos</h3> + +<pre class="brush: js notranslate">function sanitise(x) { + if (isNaN(x)) { + return Number.NaN; + } + return x; +}</pre> + +<h3 id="Testing_against_NaN">Testing against NaN</h3> + +<p>See <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN#Testing_against_NaN">Testing against NaN</a> on the <code>NaN</code> page.</p> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.nan', 'Number.NaN')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</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.Number.NaN")}}</p> + +<h2 id="Tambien_mira">Tambien mira</h2> + +<ul> + <li>El objeto global {{jsxref("NaN")}} .</li> + <li>El objeto {{jsxref("Number")}} al que pertenece.</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/negative_infinity/index.html b/files/es/web/javascript/reference/global_objects/number/negative_infinity/index.html new file mode 100644 index 0000000000..5103aa5df2 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/negative_infinity/index.html @@ -0,0 +1,118 @@ +--- +title: Number.NEGATIVE_INFINITY +slug: Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY +tags: + - JavaScript + - Number + - Property +translation_of: Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/NEGATIVE_INFINITY +--- +<div> + {{JSRef("Objetos_globales", "Number")}}</div> +<h2 id="Summary" name="Summary">Resumen</h2> +<p>La propiedad <code><strong>Number.NEGATIVE_INFINITY</strong></code> representa el valor del infinito negativo.</p> +<p>No se tiene que crear un objeto {{jsxref("Number")}} para acceder a esta propiedad estática (use <code>Number.NEGATIVE_INFINITY</code>).</p> +<p>{{js_property_attributes(0,0,0)}}</p> +<h2 id="Description" name="Description">Descripción</h2> +<p>El valor <code>Number.NEGATIVE_INFINITY</code> es el mismo que el valor negativo de la propiedad del objeto global {{jsxref( "Infinity")}}<strong><code>.</code></strong></p> +<p>Este valor tiene un comportamiento ligeramente diferente que el del infinito matematico:</p> +<ul> + <li>Cualquier valor positivo, incluyendo <code>POSITIVE_INFINITY</code>, multiplicado por <code>NEGATIVE_INFINITY</code> da como resultado <code>NEGATIVE_INFINITY</code>.</li> + <li>Cualquier valor negativo, incluyendo <code>NEGATIVE_INFINITY</code>, multiplicado por <code>NEGATIVE_INFINITY</code> da como resultado <code>POSITIVE_INFINITY</code>.</li> + <li>Cero multiplicado por <code>NEGATIVE_INFINITY</code> da como resultado <code>NaN</code>.</li> + <li>NaN multiplicado por <code>NEGATIVE_INFINITY</code> da como resultado <code>NaN</code>.</li> + <li><code>NEGATIVE_INFINITY</code>, divido por cualquier valor negativo excepto <code>NEGATIVE_INFINITY</code>, da como resultado <code>POSITIVE_INFINITY</code>.</li> + <li><code>NEGATIVE_INFINITY</code>, divido por cualquier valor positivo excepto <code>POSITIVE_INFINITY</code>, da como resultado <code>NEGATIVE_INFINITY</code>.</li> + <li><code>NEGATIVE_INFINITY</code>, divido por <code>NEGATIVE_INFINITY</code> o por <code>POSITIVE_INFINITY</code>, da como resultado <code>NaN</code>.</li> + <li>Cualquier numero divido por <code>NEGATIVE_INFINITY</code> da como resultado cero.</li> +</ul> +<p>Muchos métodos JavaScript (tales como el constructor del objeto <code>Number</code>, <code>parseFloat</code>, y <code>parseInt</code>) retornan <code>NaN</code> si el valor especifico en el párametro es significativamente menor a <code>Number.MIN_VALUE</code>.</p> +<p>Podrías utilizar la propiedad <code>Number.NEGATIVE_INFINITY</code> para indicar una condición de error que retorne un numero finito en caso de que esto suceda. Note, sin embargo, que <code><a href="/es/docs/Referencia_de_JavaScript_1.5/Funciones_globales/isFinite">isFinite</a></code> seria mas apropiado en estos casos.</p> +<h2 id="Example" name="Example">Example</h2> +<p>En el siguiente ejemplo, a la variable <code>smallNumber </code>se le asigna un valor mucho mas pequeño al valor minimo. Cuando la sentencia <code>if</code> es ejecutada, <code>smallNumber </code>tiene el valor "<code>-Infinity</code>", por lo cual a <code>smallNumber </code>le es asignado un valor finito mas manejable antes de continuar.</p> +<pre class="brush:js">var smallNumber = (-Number.MAX_VALUE) * 2 + +if (smallNumber === Number.NEGATIVE_INFINITY) { + smallNumber = returnFinite(); +} +</pre> +<h2 id="Especificaciones">Especificaciones</h2> +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificaciones</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>ECMAScript 1ra Edición. Implementado en JavaScript 1.1</td> + <td>Estándar</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.3.5', 'Number.NEGATIVE_INFINITY')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.negative_infinity', 'Number.NEGATIVE_INFINITY')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> +<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2> +<p>{{ CompatibilityTable() }}</p> +<div id="compat-desktop"> + <table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Soporte básico</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + </tr> + </tbody> + </table> +</div> +<div id="compat-mobile"> + <table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Soporte básico</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + </tr> + </tbody> + </table> +</div> +<h2 id="See_also" name="See_also">Ver también</h2> +<ul> + <li>{{jsxref("Number.POSITIVE_INFINITY")}}</li> + <li>{{jsxref( "Infinity")}}</li> + <li>{{jsxref("isFinite")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/parsefloat/index.html b/files/es/web/javascript/reference/global_objects/number/parsefloat/index.html new file mode 100644 index 0000000000..d4797cfe3f --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/parsefloat/index.html @@ -0,0 +1,77 @@ +--- +title: Number.parseFloat() +slug: Web/JavaScript/Reference/Global_Objects/Number/parseFloat +tags: + - ECMAScript2015 + - ECMAScript6 + - JavaScript + - Número + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseFloat +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/parseFloat +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>Number.parseFloat()</code></strong> parsea un argumento cadena y regresa un número de punto flotante. Este método se comporta de igual forma a la función global {{jsxref("parseFloat", "parseFloat()")}} y es parte de ECMAScript 2015 (su propósito es la modularización de los globales).</p> + +<div>{{EmbedInteractiveExample("pages/js/number-parsefloat.html")}}</div> + + + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox notranslate"><code>Number.parseFloat(<var>string</var>)</code></pre> + +<h3 id="Parámetros">Parámetros</h3> + +<p>{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat", "Parameters")}}</p> + +<h3 id="Valor_de_regreso">Valor de regreso</h3> + +<p>{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat", "Return value")}}</p> + +<h2 id="Descripción">Descripción</h2> + +<p>Por favor ver {{jsxref("parseFloat", "parseFloat()")}} para más detalles y ejemplos.</p> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js notranslate">if (Number.parseFloat === void 0) { + Number.parseFloat = parseFloat; +} +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estatus</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-number.parsefloat', 'Number.parseFloat')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Definición inicial</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.parsefloat', 'Number.parseFloat')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_del_navegador">Compatibilidad del navegador</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.Number.parseFloat")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>El objeto {{jsxref("Number")}} al que pertenece.</li> + <li>El método global {{jsxref("parseFloat", "parseFloat()")}}.</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/parseint/index.html b/files/es/web/javascript/reference/global_objects/number/parseint/index.html new file mode 100644 index 0000000000..5d2120ca5b --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/parseint/index.html @@ -0,0 +1,81 @@ +--- +title: Number.parseInt() +slug: Web/JavaScript/Reference/Global_Objects/Number/parseInt +tags: + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseInt +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/parseInt +--- +<div>{{JSRef}}</div> + +<p>The <strong><code>Number.parseInt()</code></strong> method parses a string argument and returns an integer of the specified radix or base.</p> + +<p>The <strong><code>Number.parseInt()</code></strong> El método Number.parseInt () analiza un argumento de cadena y devuelve un entero de la raíz o base especificada.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-parseint.html", "taller")}}</div> + + + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">Number.parseInt(<var>string,</var>[ <var>radix</var>])</pre> + +<h3 id="Parameters">Parameters</h3> + +<div> +<dl> + <dt><code><var>string</var></code></dt> + <dd>The value to parse. If this argument is not a string, then it is converted to one using the <code><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></code> abstract operation. Leading whitespace in this argument is ignored.</dd> + <dt><code><var>radix</var></code><var> {{optional_inline}}</var></dt> + <dd>An integer between <code>2</code> and <code>36</code> that represents the <em>radix</em> (the base in mathematical numeral systems) of the <code><var>string</var></code>. Be careful—this does <strong><em>not</em></strong> default to <code>10</code>!</dd> +</dl> +</div> + +<h3 id="Return_value">Return value</h3> + +<p>An integer parsed from the given <code><var>string</var></code>.</p> + +<p>If the <code><var>radix</var></code> is smaller than <code>2</code> or bigger than <code>36</code>, and the first non-whitespace character cannot be converted to a number, {{jsxref("NaN")}} is returned.</p> + +<h2 id="Description">Description</h2> + +<p>This method has the same functionality as the global {{jsxref("parseInt", "parseInt()")}} function:</p> + +<pre class="brush: js">Number.parseInt === parseInt // true</pre> + +<p>and is part of ECMAScript 2015 (its purpose is modularization of globals). Please see {{jsxref("parseInt", "parseInt()")}} for more detail and examples.</p> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">if (Number.parseInt === undefined) { + Number.parseInt = window.parseInt +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.parseint', 'Number.parseInt')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("javascript.builtins.Number.parseInt")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>The {{jsxref("Number")}} object it belongs to.</li> + <li>The global {{jsxref("parseInt", "parseInt()")}} method.</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/positive_infinity/index.html b/files/es/web/javascript/reference/global_objects/number/positive_infinity/index.html new file mode 100644 index 0000000000..72c482b252 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/positive_infinity/index.html @@ -0,0 +1,116 @@ +--- +title: Number.POSITIVE_INFINITY +slug: Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY +tags: + - JavaScript + - Number + - Property +translation_of: Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/POSITIVE_INFINITY +--- +<p>{{JSRef("Objetos_globales", "Number")}}</p> +<h2 id="Resumen">Resumen</h2> +<p>La propiedad <code><strong>Number.POSITIVE_INFINITY</strong></code> representa el infinito positivo.</p> +<p>No se tiene que crear un objeto {{jsxref("Number")}} para acceder a esta propiedad estática (use <code>Number.POSITIVE_INFINITY</code>).</p> +<p>{{js_property_attributes(0,0,0)}}</p> +<h2 id="Descripción">Descripción</h2> +<p>El valor de <code>Number.POSITIVE_INFINITY</code> es el mismo valor de la propiedad {{jsxref( "Infinity")}} del objeto global.</p> +<p>Este valor tiene un comportamiento ligeramente diferente al infinio matemático:</p> +<ul> + <li>Cualquier valor positivo, incluyendo <code>POSITIVE_INFINITY</code>, multiplicado por <code>POSITIVE_INFINITY</code> da como resultado <code>POSITIVE_INFINITY</code>.</li> + <li>Cualquier valor negativo, incluyendo <code>NEGATIVE_INFINITY</code>, multiplicado por <code>POSITIVE_INFINITY</code> da como resultado <code>NEGATIVE_INFINITY</code>.</li> + <li>Cero multiplicado por <code>POSITIVE_INFINITY</code> da como resultado NaN.</li> + <li>NaN multiplicado por <code>POSITIVE_INFINITY</code> da como resultado NaN.</li> + <li><code>POSITIVE_INFINITY</code>, dividido por cualquier valor negativo excepto <code>NEGATIVE_INFINITY</code>, da como resultado <code>NEGATIVE_INFINITY</code>.</li> + <li><code>POSITIVE_INFINITY</code>, divido por cualquier valor positivo excepto <code>POSITIVE_INFINITY</code>, da como resultado <code>POSITIVE_INFINITY</code>.</li> + <li><code>POSITIVE_INFINITY</code>, divido por <code>INFINITY</code> o por <code>POSITIVE_INFINITY</code>, da como resultado NaN.</li> + <li>Cualquier numero divido por <code>POSITIVE_INFINITY</code> da como resultado cero.</li> +</ul> +<p>Muchos métodos de JavaScript (tales como el constructor del objeto <code>Number</code>, <code>parseFloat</code> y <code>parseInt</code>) retornan <code>NaN</code> si el valor especificado en el parámetro es signficativamente mayor a <code>Number.MAX_VALUE</code>.</p> +<p>Podrías utilizar la propiedad <code>Number.POSITIVE_INFINITY</code> para indicar una condición de error que retorne un numero finito en caso de que esto suceda. Note, sin embargo, que <code><a href="/es/docs/Referencia_de_JavaScript_1.5/Funciones_globales/isFinite">isFinite</a></code> seria mas apropiado en estos casos.</p> +<h2 id="Ejemplo">Ejemplo</h2> +<p>En el siguiente ejemplo, a la variable <code>bigNumber </code>se le asigna un valor mucho mayor al valor máximo. Cuando la sentencia <code>if</code> es ejecutada, <code>bigNumber </code>tiene el valor "<code>Infinity</code>", por lo cual a <code>bigNumber</code> le es asignado un valor mas manejable antes de continuar.</p> +<pre class="brush: js">var bigNumber = Number.MAX_VALUE * 2; +if (bigNumber === Number.POSITIVE_INFINITY) { + bigNumber = returnFinite(); +} +</pre> +<h2 id="Especificaciones">Especificaciones</h2> +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificaciones</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td> + <td>Estándar</td> + <td>Definición inicial.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.3.6', 'Number.POSITIVE_INFINITY')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.positive_infinity', 'Number.POSITIVE_INFINITY')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> +<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2> +<p>{{ CompatibilityTable() }}</p> +<div id="compat-desktop"> + <table class="compat-table"> + <tbody> + <tr> + <th>Caracteristica</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Soporte básico</td> + <td>(SI)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + </tr> + </tbody> + </table> +</div> +<div id="compat-mobile"> + <table class="compat-table"> + <tbody> + <tr> + <th>Caracteristica</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Soprote básico</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + <td>(Si)</td> + </tr> + </tbody> + </table> +</div> +<h2 id="See_also" name="See_also">Ver también</h2> +<ul> + <li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li> + <li>{{jsxref("Infinity")}}</li> + <li>{{jsxref("isFinite")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/tofixed/index.html b/files/es/web/javascript/reference/global_objects/number/tofixed/index.html new file mode 100644 index 0000000000..429a8f5a85 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/tofixed/index.html @@ -0,0 +1,148 @@ +--- +title: Number.prototype.toFixed() +slug: Web/JavaScript/Reference/Global_Objects/Number/toFixed +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toFixed +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/toFixed +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>toFixed()</code></strong> formatea un número usando notación de punto fijo.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-tofixed.html")}}</div> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><code><var>numObj</var>.toFixed([<var>digitos</var>])</code></pre> + +<h3 id="Parametros">Parametros</h3> + +<dl> + <dt><code>digitos</code></dt> + <dd>Opcional. El número de digitos que aparecen después del punto decimal; este puede ser un valor entre 0 y 20, inclusive, algunas implementaciones pueden soportar un rango más amplio de valores. Si el argumento es omitido, es tratado como 0.</dd> +</dl> + +<h3 id="Valor_Devuelto">Valor Devuelto</h3> + +<p>Una cadena que representa el número dado, usando notación de punto fijo.</p> + +<h3 id="Excepciones">Excepciones</h3> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>Si <code>digits</code> es demasiado pequeño o demasiado grande. Los valores entre 0 y 20, inclusive, no causarán un error tipo<code> {{jsxref("RangeError")}}</code>. Las implementaciones también pueden admitir valores cada vez más grandes.</dd> + <dt>{{jsxref("TypeError")}}</dt> + <dd>Si este método se invoca en un objeto que no es un {{jsxref("Number")}}.</dd> +</dl> + +<h2 id="Descripción">Descripción</h2> + +<p><strong><code>toFixed()</code></strong> devuelve una representación de cadena de <code> numObj </code> que no usa notación exponencial y tiene exactamente <code> dígitos </code> dígitos después del decimal. El número se redondea si es necesario, y la parte fraccional se rellena con ceros si es necesario para que tenga la longitud especificada.Si <code>numObj</code> es mayor que <code>1e+21</code>, este metodo llama a {{jsxref("Number.prototype.toString()")}} y retorna una cadena de notacion exponencial.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Using_toFixed">Using <code>toFixed</code></h3> + +<pre class="brush: js">var numObj = 12345.6789; + +numObj.toFixed(); // Returns '12346': note rounding, no fractional part +numObj.toFixed(1); // Returns '12345.7': note rounding +numObj.toFixed(6); // Returns '12345.678900': note added zeros +(1.23e+20).toFixed(2); // Returns '123000000000000000000.00' +(1.23e-10).toFixed(2); // Returns '0.00' +2.34.toFixed(1); // Returns '2.3' +2.35.toFixed(1); // Returns '2.4'. Note that it rounds up in this case. +-2.34.toFixed(1); // Returns -2.3 (due to operator precedence, negative number literals don't return a string...) +(-2.34).toFixed(1); // Returns '-2.3' (...unless you use parentheses) +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES3')}}</td> + <td>{{Spec2('ES3')}}</td> + <td>Initial definition. Implemented in JavaScript 1.5.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.4.5', 'Number.prototype.toFixed')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.prototype.tofixed', 'Number.prototype.toFixed')}}</td> + <td>{{Spec2('ES6')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.prototype.tofixed', 'Number.prototype.toFixed')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("Number.prototype.toExponential()")}}</li> + <li>{{jsxref("Number.prototype.toPrecision()")}}</li> + <li>{{jsxref("Number.prototype.toString()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/tolocalestring/index.html b/files/es/web/javascript/reference/global_objects/number/tolocalestring/index.html new file mode 100644 index 0000000000..c0d411b844 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/tolocalestring/index.html @@ -0,0 +1,156 @@ +--- +title: Number.prototype.toLocaleString() +slug: Web/JavaScript/Reference/Global_Objects/Number/toLocaleString +tags: + - Internacionalizacion + - JavaScript + - Número +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toLocaleString +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/toLocaleString +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>toLocaleString()</code></strong> retorna una representacion localizada del número en forma de texto</p> + +<div>{{EmbedInteractiveExample("pages/js/number-tolocalestring.html")}}</div> + + + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox notranslate"><code><em>numObj</em>.toLocaleString(</code><code>[locales [, options]])</code></pre> + +<h3 id="Parametros">Parametros</h3> + +<p>Los argumentos <code>locales</code> y <code>options</code> personalizan el comportamiento de la funcion y permite especificar el lenguaje cuyo formato deberá ser utilizado. En implementaciones, que ignoran los argumentos <code>locales</code> y <code>options</code> la localización utilizada y la forma del texto retornado es enteramente dependiente de la implementación.</p> + +<div>Mira el <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat">constructor Intl.NumberFormat()</a> para ver más detalles sobre los parámetros y como se utilizan.</div> + +<div></div> + +<h3 id="Valor_de_retorno">Valor de retorno</h3> + +<p>Un texto con una representación localizada del número dado.</p> + +<h2 id="Performance">Performance</h2> + +<p>Cuando formateas una gran cantidad de números, es mejor crear un objeto {{jsxref("NumberFormat")}} y utilizar la función {{jsxref("NumberFormat.format")}}.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Usando_toLocaleString">Usando <code>toLocaleString</code></h3> + +<p>Un uso básico sin especificar <code>locales</code>, retorna un texto formateado con el <code>locales</code> y <code>options</code> por defecto.</p> + +<pre class="brush: js notranslate">var number = 3500; + +console.log(number.toLocaleString()); // Muestra "3,500" si se está utilizando la localización U.S. English +</pre> + +<h3 id="Verificando_el_soporte_de_los_parámetros_locales_y_options">Verificando el soporte de los parámetros <code>locales</code> y <code>options</code></h3> + +<p>Los parámetros <code>locales</code> y <code>options</code> no son soportados aún por todos los navegadores. Para verificar el soporte en ES5.1 y posteriores implementaciones, se puede utilizar el hecho que los tags inválidos en la localización son rechazados con una excepción {{jsxref("Global_Objects/RangeError", "RangeError")}}:</p> + +<pre class="brush: js notranslate">function toLocaleStringSupportsLocales() { + var number = 0; + try { + number.toLocaleString('i'); + } catch (e) { + return e.name === 'RangeError'; + } + return false; +} +</pre> + +<p>Antes de ES5.1, las implementaciones no requieren devolver una exepción {{jsxref("Global_Objects/RangeError", "RangeError")}} cuando <code>toLocaleString </code>es llamado sin argumentos.</p> + +<p>Para verificar que funciona todos los navegadores, incluyendo aquellos que soportan ECMA-262, anterior a ES5.1, se puede verificar por las funcionalidades especificadas en ECMA-402 que requieren soportar opciones regionales para <code>Number.prototype.toLocaleString</code> directamente:</p> + +<pre class="brush: js notranslate">function toLocaleStringSupportsOptions() { + return !!(typeof Intl == 'object' && Intl && typeof Intl.NumberFormat == 'function'); +} +</pre> + +<p>Esta validación del objeto global <code>Intl</code> , verificar que no es <code>null</code> (nulo) y que tiene la propiedad <code>NumberFormat</code> que es una función.</p> + +<h3 id="Utilizando_locales">Utilizando <code>locales</code></h3> + +<p>Este ejemplo muestra alguna de las variaciones en los formatos de números localizados. Para obtener el formato de la localización utilizada en la interfaz del usuario de tu aplicación, asegurate de especificar la localización (y de ser posible alguna localización de respaldo) utilizando el parámetro <code>locales</code>:</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// Aleman utiliza comas como separador decimal y puntos miles +console.log(number.toLocaleString('de-DE')); +// → 123.456,789 + +// Arabe en la mayoría de países de habla Arabe utilizan numerales <a href="https://en.wikipedia.org/wiki/Eastern_Arabic_numerals">Eastern Arabic</a> +console.log(number.toLocaleString('ar-EG')); +// → ١٢٣٤٥٦٫٧٨٩ + +// India utiliza separadores de miles/lakh/crore +console.log(number.toLocaleString('en-IN')); +// → 1,23,456.789 + +// la extensión nu requiere un sistema numerico, e.g. Decimales Chino +console.log(number.toLocaleString('zh-Hans-CN-u-nu-hanidec')); +// → 一二三,四五六.七八九 + +// cuando solicitas un lenguage que podria no ser soportado, como +// Balinese, incluye un lenguaje de respaldo, en este caso Indonesio +console.log(number.toLocaleString(['ban', 'id'])); +// → 123.456,789 +</pre> + +<h3 id="Utilizando_options">Utilizando <code>options</code></h3> + +<p>El resultado proveido por <code>toLocaleString</code> puede ser personalizado utilizando el parámetro <code>options</code> :</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// solicitar un formato de moneda +console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' })); +// → 123.456,79 € + +// en Japones yen no utiliza una moneda menor +console.log(number.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' })) +// → ¥123,457 + +// limitar a tres digitos el significante +console.log(number.toLocaleString('en-IN', { maximumSignificantDigits: 3 })); +// → 1,23,000 + +// Utilizar el lenguaje por defecto del host con opciones para el formato del número +var num = 30000.65; +console.log(num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})); +// → "30,000.65" donde English es el lenguaje por defecto, o +// → "30.000,65" donde Aleman es el lenguaje por defecto, o +// → "30 000,65" donde French es el lenguaje por defecto +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.prototype.tolocalestring', 'Number.prototype.toLocaleString')}}</td> + </tr> + <tr> + <td>{{SpecName('ES Int Draft', '#sup-number.prototype.tolocalestring', 'Number.prototype.toLocaleString')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegadores">Compatibilidad de navegadores</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.Number.toLocaleString")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number.prototype.toString()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/toprecision/index.html b/files/es/web/javascript/reference/global_objects/number/toprecision/index.html new file mode 100644 index 0000000000..b8133df255 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/toprecision/index.html @@ -0,0 +1,103 @@ +--- +title: Number.prototype.toPrecision() +slug: Web/JavaScript/Reference/Global_Objects/Number/toPrecision +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toPrecision +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/toPrecision +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>toPrecision()</code></strong> devuelve una cadena que representa un objeto {{jsxref("Number")}} según la precisión especificada.</p> + +<div>{{EmbedInteractiveExample("pages/js/number-toprecision.html")}}</div> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><var>numObj</var>.toPrecision([<var>precision</var>])</pre> + +<h3 id="Parámetros">Parámetros</h3> + +<dl> + <dt><code>precision</code></dt> + <dd>Opcional. Un entero que especifica el número de digitos significativos.</dd> +</dl> + +<h3 id="Valor_devuelto">Valor devuelto</h3> + +<p>Una cadena que representa un objeto {{jsxref("Number")}} en punto fijo o en notación exponencial redondeada a <code>precision</code> de digitos significativos. Vea la discusión acerca del redondeo en la descripción del método {{jsxref("Number.prototype.toFixed()")}} , que además aplica a <code>toPrecision()</code>.</p> + +<p>Si el parámetro <code>precision</code> es omitido, se comporta como {{jsxref("Number.prototype.toString()")}}. Si el parámetro <code>precision</code> es un valor no entero, el valor es redondeado al entero más cercano.</p> + +<h3 id="Exceptions">Exceptions</h3> + +<dl> + <dt>{{jsxref("Global_Objects/RangeError", "RangeError")}}</dt> + <dd>If <code>precision</code> is not between 1 and 100 (inclusive), a {{jsxref("RangeError")}} is thrown. Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits.</dd> +</dl> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Usando_toPrecision">Usando <code>toPrecision</code></h3> + +<pre class="brush: js">var numObj = 5.123456; + +console.log(numObj.toPrecision()); // logs '5.123456' +console.log(numObj.toPrecision(5)); // logs '5.1235' +console.log(numObj.toPrecision(2)); // logs '5.1' +console.log(numObj.toPrecision(1)); // logs '5' + +numObj = 0.000123 + +console.log(numObj.toPrecision()); // logs '0.000123' +console.log(numObj.toPrecision(5)); // logs '0.00012300' +console.log(numObj.toPrecision(2)); // logs '0.00012' +console.log(numObj.toPrecision(1)); // logs '0.0001' + +// observe que bajo algunas circunstancias el valor retornado es en notación exponencial +console.log((1234.5).toPrecision(2)); // logs '1.2e+3' +</pre> + +<h2 id="Especificaciónes">Especificaciónes</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificación</th> + <th scope="col">Estado</th> + <th scope="col">Comentario</th> + </tr> + <tr> + <td>{{SpecName('ES3')}}</td> + <td>{{Spec2('ES3')}}</td> + <td>Primera definición. Implementada en JavaScript 1.5.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.4.7', 'Number.prototype.toPrecision')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.prototype.toprecision', 'Number.prototype.toPrecision')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.prototype.toprecision', 'Number.prototype.toPrecision')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_de_navegadores">Compatibilidad de navegadores</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.Number.toPrecision")}}</p> + +<h2 id="Vea_También">Vea También</h2> + +<ul> + <li>{{jsxref("Number.prototype.toFixed()")}}</li> + <li>{{jsxref("Number.prototype.toExponential()")}}</li> + <li>{{jsxref("Number.prototype.toString()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/tostring/index.html b/files/es/web/javascript/reference/global_objects/number/tostring/index.html new file mode 100644 index 0000000000..58821a4423 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/tostring/index.html @@ -0,0 +1,64 @@ +--- +title: Number.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Number/toString +tags: + - JavaScript + - Method + - Number + - Prototype + - Referencia +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toString +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/toString +--- +<div>{{JSRef("Objetos_globales", "Number")}}</div> + +<h2 id="Resumen" name="Resumen">Resumen</h2> + +<p>Devuelve una cadena que representa al objeto <em>Number</em> especificado</p> + +<h2 id="Sintaxis" name="Sintaxis">Sintaxis</h2> + +<p><code><em>number</em> .toString( {{ mediawiki.external('<em>base</em> ') }} )</code></p> + +<h3 id="Par.C3.A1metro" name="Par.C3.A1metro">Parámetro</h3> + +<dl> + <dt>base</dt> + <dd>Un entero entre 2 y 36 especificando la base a usar para representar los valores numéricos.</dd> +</dl> + +<h3 id="Devuelve" name="Devuelve">Devuelve</h3> + +<p>Una cadena que representa al objeto.</p> + +<h2 id="Descripci.C3.B3n" name="Descripci.C3.B3n">Descripción</h2> + +<p>El objeto <code>Number</code> sobreescribe el método <code>toString</code> y no lo hereda del objeto {{jsxref("Object")}}; por tanto no hereda {{jsxref("Object.prototype.toString()")}}. Para objetos <code>Number</code>, el método <code>toString</code> devuelve una cadena que representa al objeto en la base especificada.</p> + +<p>El método toString comprueba su primer argumento, e intenta devolver una cadena de representación en la base especificada. Para bases superiores a 10, las letras del alfabeto indican numerales mayores de 9. Por ejemplo, para números hexadecimales (base 16), se utiliza de A hasta F.</p> + +<p>Si no se da a toString una base entre 2 y 36, se lanza una excepción.</p> + +<p>Si no se especifica la base, JavaScript asume la base predefinida, que es 10.</p> + +<h2 id="Ejemplos" name="Ejemplos">Ejemplos</h2> + +<pre class="brush: js">var howMany = 10; + +alert("howMany.toString() is " + howMany.toString()); // displays "10" + +alert("45 .toString() is " + 45 .toString()); //displays "45" + +var x = 7; +alert(x.toString(2)) // Displays "111" +</pre> + + + +<h2 id="Vea_Tambi.C3.A9n" name="Vea_Tambi.C3.A9n">Vea También</h2> + +<ul> + <li>{{jsxref("Number.prototype.toFixed()")}}</li> + <li>{{jsxref("Number.prototype.toExponential()")}}</li> + <li>{{jsxref("Number.prototype.toPrecision()")}}</li> +</ul> diff --git a/files/es/web/javascript/reference/global_objects/number/valueof/index.html b/files/es/web/javascript/reference/global_objects/number/valueof/index.html new file mode 100644 index 0000000000..5ee896c1f7 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/number/valueof/index.html @@ -0,0 +1,82 @@ +--- +title: Number.prototype.valueOf() +slug: Web/JavaScript/Reference/Global_Objects/Number/valueOf +tags: + - JavaScript + - Métodos + - Number + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Number/valueOf +original_slug: Web/JavaScript/Referencia/Objetos_globales/Number/valueOf +--- +<div>{{JSRef}}</div> + +<p>El método <strong><code>valueOf()</code></strong> retorna el valor primitivo inserto en un objeto {{jsxref("Number")}}.</p> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><code><var>numObj</var>.valueOf()</code></pre> + +<h3 id="Valor_retornado">Valor retornado</h3> + +<p>Un número representando al valor primitivo del objeto {{jsxref("Number")}} especificado.</p> + +<h2 id="Descripción">Descripción</h2> + +<p>Este método es usualmente llamado de forma interna por JavaScript y no es explicitado en el código web.</p> + +<h2 id="Ejemplos">Ejemplos</h2> + +<h3 id="Utilizando_valueOf">Utilizando <code>valueOf</code></h3> + +<pre class="brush: js">var numObj = new Number(10); +console.log(typeof numObj); // objeto + +var num = numObj.valueOf(); +console.log(num); // 10 +console.log(typeof num); // número +</pre> + +<h2 id="Especificaciones">Especificaciones</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definición inicial. Implementado en JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.4.4', 'Number.prototype.valueOf')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.prototype.valueof', 'Number.prototype.valueOf')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.prototype.valueof', 'Number.prototype.valueOf')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilidad_con_navegador">Compatibilidad con navegador</h2> + +<p class="hidden">La tabla de compatibilidad en esta página es generada desde datos estructurados. Si deseas contribuir con los datos, por favor, revisa <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> y envíanos una solicitud.</p> + +<p>{{Compat("javascript.builtins.Number.valueOf")}}</p> + +<h2 id="Ver_también">Ver también</h2> + +<ul> + <li>{{jsxref("Number.prototype.toSource()")}}</li> +</ul> |