diff options
| author | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:45:12 +0100 |
|---|---|---|
| committer | Florian Merz <me@fiji-flo.de> | 2021-02-11 14:45:12 +0100 |
| commit | cb9e359a51c3249d8f5157db69d43fd413ddeda6 (patch) | |
| tree | ae3040d626c3b5717da5bda2af9f0a9ff9bd389f /files/ca/web/javascript/reference/global_objects/number | |
| parent | 8260a606c143e6b55a467edf017a56bdcd6cba7e (diff) | |
| download | translated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.tar.gz translated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.tar.bz2 translated-content-cb9e359a51c3249d8f5157db69d43fd413ddeda6.zip | |
unslug ca: move
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/number')
19 files changed, 2356 insertions, 0 deletions
diff --git a/files/ca/web/javascript/reference/global_objects/number/epsilon/index.html b/files/ca/web/javascript/reference/global_objects/number/epsilon/index.html new file mode 100644 index 0000000000..5e3f602703 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/epsilon/index.html @@ -0,0 +1,102 @@ +--- +title: Number.EPSILON +slug: Web/JavaScript/Referencia/Objectes_globals/Number/EPSILON +translation_of: Web/JavaScript/Reference/Global_Objects/Number/EPSILON +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La propietat <strong><code>Number.EPSILON</code></strong> representa la diferència entre el nombre 1 i el valor més petit major que 1 que pot ser representat com un {{jsxref("Global_Objects/Number", "Number")}}.</p> + +<p>Per tal d'accedir a la propietat no es fa necessari crear un objecte {{jsxref("Global_Objects/Number", "Number")}} ja que és una propietat estàtica i n'hi ha prou amb fer servir <code>Number.EPSILON</code> per a obtindre el valor.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>La propietat <code>EPSILON</code> té un valor aproximat de <code>2.2204460492503130808472633361816E-16</code>, és a dir, <code>2<sup>-52</sup></code>.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Exemple_Comprovant_l'igualtat">Exemple: Comprovant l'igualtat</h3> + +<pre class="brush: js">x = 0.2; +y = 0.3; +equal = (Math.abs(x - y) < Number.EPSILON); +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-15.7.3.7', 'Number.EPSILON')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("25.0")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile("25.0")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also" name="See_also">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Global_Objects/Number", "Number")}} al qual pertany.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/index.html b/files/ca/web/javascript/reference/global_objects/number/index.html new file mode 100644 index 0000000000..5f4b7a0bb2 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/index.html @@ -0,0 +1,214 @@ +--- +title: Number +slug: Web/JavaScript/Referencia/Objectes_globals/Number +translation_of: Web/JavaScript/Reference/Global_Objects/Number +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>L'objecte de JavaScript <strong><code>Number</code></strong> és un objecte embolcall que permet treballar amb valors numèrics. Un objecte de tipus <code>Number</code> és creat quan es crida el constructor <code>Number()</code>.</p> + +<h2 id="Syntax" name="Syntax">Constructor</h2> + +<pre class="syntaxbox">new Number(valor);</pre> + +<h3 id="Parameters" name="Parameters">Paràmetres</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor numèric de l'objecte que es pretèn crear.</dd> +</dl> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>Els usos pricipals de l'objecte <code>Number</code> són:</p> + +<ul> + <li>Si l'argument dona al constructor no es pot convertir en un nombre aquest retorna {{jsxref("Global_Objects/NaN", "NaN")}}.</li> + <li><code>Number</code> pot ser emprat per a realitzar conversions de tipus sense necesitat de crear un nou objecte.</li> +</ul> + +<h2 id="Properties" name="Properties">Propietats</h2> + +<dl> + <dt>{{jsxref("Number.EPSILON")}} {{experimental_inline}}</dt> + <dd>L'interval més petit entre dos nombres que es pot representar.</dd> + <dt>{{jsxref("Number.MAX_SAFE_INTEGER")}} {{experimental_inline}}</dt> + <dd>El nombre sencer més gran que JavaScript pot representar de forma segura (<code>2<sup>53</sup> - 1</code>).</dd> + <dt>{{jsxref("Number.MAX_VALUE")}}</dt> + <dd>El nombre positiu més gran que pot ésser representat.</dd> + <dt>{{jsxref("Number.MIN_SAFE_INTEGER")}} {{experimental_inline}}</dt> + <dd>El nombre més petit que JavaScript pot representar de forma segura (<code>-(2<sup>53</sup> - 1)</code>).</dd> + <dt>{{jsxref("Number.MIN_VALUE")}}</dt> + <dd>El nombre positiu més petit que pot ésser representat. És a dir, el nombre positiu més proper a zero sense arribar a ser zero.</dd> + <dt>{{jsxref("Number.NaN")}}</dt> + <dd>El valor especial "not a number".</dd> + <dt>{{jsxref("Number.NEGATIVE_INFINITY")}}</dt> + <dd>El valor especial que representa l'infinit negatiu. És retornat quan es produeix un <em>overflow</em>.</dd> + <dt>{{jsxref("Number.POSITIVE_INFINITY")}}</dt> + <dd>El valor especial que representa l'infinit positiu. És retornat quan es produeix un <em>overflow</em>.</dd> + <dt>{{jsxref("Number.prototype")}}</dt> + <dd>Permet l'adició de propietats a l'objecte <code>Number</code>.</dd> +</dl> + +<div>{{jsOverrides("Function", "properties", "MAX_VALUE", "MIN_VALUE", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY", "protoype")}}</div> + +<h2 id="Methods" name="Methods">Mètodes</h2> + +<dl> + <dt>{{jsxref("Number.isNaN()")}} {{experimental_inline}}</dt> + <dd>Determina si el valor proporcionat és NaN.</dd> + <dt>{{jsxref("Number.isFinite()")}} {{experimental_inline}}</dt> + <dd>Determina si el valor que representa és un valor finit.</dd> + <dt>{{jsxref("Number.isInteger()")}} {{experimental_inline}}</dt> + <dd>Determina si el valor que representa és un nombre i si es tracta d'un nombre sencer.</dd> + <dt>{{jsxref("Number.isSafeInteger()")}} {{experimental_inline}}</dt> + <dd>Determina si el tipus del valor proporcionat així com el valor en sí mateix és un nombre sencer segur (nombre entre <code>-(2<sup>53</sup> - 1)</code> i <code>2<sup>53</sup> - 1</code>).</dd> + <dt><s class="obsoleteElement">{{jsxref("Number.toInteger()")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Utilitzat per evaluar el valor passat i convertir-lo a sencer (o bé {{jsxref("Global_Objects/Infinity", "Infinity")}}), però s'ha eliminat.</s></dd> + <dt>{{jsxref("Number.parseFloat()")}} {{experimental_inline}}</dt> + <dd>Fa la mateixa funció que el mètode {{jsxref("Global_Objects/parseFloat", "parseFloat")}} de l'objecte global.</dd> + <dt>{{jsxref("Number.parseInt()")}} {{experimental_inline}}</dt> + <dd>Fa la mateixa funció que el mètode {{jsxref("Global_Objects/parseInt", "parseInt")}} de l'objecte global.</dd> +</dl> + +<div>{{jsOverrides("Function", "Methods", "isNaN")}}</div> + +<h2 id="Number_instances" name="Number_instances"><code>Instàncies de Number</code></h2> + +<p>Totes les instàncies de <code>Number</code> hereten de {{jsxref("Number.prototype")}}. L'objecte prototype del constructor <code>Number</code> pot ser modificat per a afectar a totes les instàncies de <code>Number</code>.</p> + +<h3 id="Methods_of_Number_instance" name="Methods_of_Number_instance">Mètodes</h3> + +<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/prototype', 'Methods')}}</div> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Example:_Using_the_Number_object_to_assign_values_to_numeric_variables" name="Example:_Using_the_Number_object_to_assign_values_to_numeric_variables">Exemple: Utilitzar l'objecte <code>Number</code> per a assignar valors numèrics a variables</h3> + +<p>L'exemple que trobareu a continuació utilitza les propietats de l'objecte <code>Number</code> per a assignar valors a diferents variables numèriques:</p> + +<pre class="brush: js">var biggestNum = Number.MAX_VALUE; +var smallestNum = Number.MIN_VALUE; +var infiniteNum = Number.POSITIVE_INFINITY; +var negInfiniteNum = Number.NEGATIVE_INFINITY; +var notANum = Number.NaN; +</pre> + +<h3 id="Example:_Using_Number_to_convert_a_Date_object" name="Example:_Using_Number_to_convert_a_Date_object">Exemple: Rang de sencers de <code>Number</code></h3> + +<p>El següent exemple mostra el valor sencer mínim i màxim que pot ésser representat per un objecte de tipus <code>Number</code> (per a més detalls, referiu-vos a l'standard EcmaScript, capítol <em>8.5 El tipus Number</em>):</p> + +<pre class="brush: js">var biggestInt = 9007199254740992; +var smallestInt = -9007199254740992; +</pre> + +<p>A l'interpretar dades que han sigut serialitzades amb JSON, els valors que queden fora d'aquest rang poden esdevenir corruptes quan l'intèrpret de JSON els forci esdevenir de tipus <code>Number</code>. Una forma d'evitar aquesta limitació és utilitzar una {{jsxref("Global_Objects/String", "String")}} per representar el nombre.</p> + +<h3 id="Example:_Using_Number_to_convert_a_Date_object" name="Example:_Using_Number_to_convert_a_Date_object">Exemple: Utilitzar <code>Number</code> per a convertir un objecte de tipus <code>Date</code></h3> + +<p>L'exemple que trobareu a continuació converteix un objecte de tipus {{jsxref("Global_Objects/Date", "Date")}} a un tipus numèric tot utilitzant <code>Number</code> com una funció:</p> + +<pre class="brush: js">var d = new Date('December 17, 1995 03:24:00'); +print(Number(d)); +</pre> + +<p>Aquest exemple mostrarà "819199440000".</p> + +<h3 id="Exemple_Convertir_cadenes_de_caràcters_numèriques_a_nombres">Exemple: Convertir cadenes de caràcters numèriques a nombres</h3> + +<pre class="brush: js">Number("123") // 123 +Number("") // 0 +Number("0x11") // 17 +Number("0b11") // 3 +Number("0o11") // 9 +Number("foo") // NaN +Number("100a") // NaN +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>ECMAScript 1a Edició.</td> + <td>Standard</td> + <td>Definició inicial. Implementat a JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7', 'Number')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number-objects', 'Number')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Afegides nous mètodes i propietats: ({{jsxref("Number.EPSILON", "EPSILON")}}, {{jsxref("Number.isFinite", "isFinite")}}, {{jsxref("Number.isInteger", "isInteger")}}, {{jsxref("Number.isNaN", "isNaN")}}, {{jsxref("Number.parseFloat", "parseFloat")}}, {{jsxref("Number.parseInt", "parseInt")}})</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadores">Compatibilitat amb navegadores</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Global_Objects/NaN", "NaN")}}</li> + <li>L'objecte global {{jsxref("Global_Objects/Math", "Math")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/isfinite/index.html b/files/ca/web/javascript/reference/global_objects/number/isfinite/index.html new file mode 100644 index 0000000000..21d9493bf8 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/isfinite/index.html @@ -0,0 +1,118 @@ +--- +title: Number.isFinite() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/isFinite +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isFinite +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>Number.isFinite()</code></strong> determina si el valor que se li passa com a argument és un nombre finit o no.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.isFinite(valor)</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor que es comprovarà si és finit.</dd> +</dl> + +<h2 id="Descripció">Descripció</h2> + +<p>En comparació amb la funció global {{jsxref("Global_Objects/isFinite", "isFinite()")}}, aquest mètode no converteix el paràmetres a un nombre forçosament. Això implica que només valors de tipus number, que també siguin finits, retornaran <code>true</code>.</p> + +<h2 id="Exemples">Exemples</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, seria true si s'utilitzés la + // funció global isFinite('0') +</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="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isfinite', 'Number.isInteger')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatChrome("19")}}</td> + <td>{{CompatGeckoDesktop("16")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatOpera("15")}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("16")}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Global_Objects/Number", "Number")}} al que pertany.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/isinteger/index.html b/files/ca/web/javascript/reference/global_objects/number/isinteger/index.html new file mode 100644 index 0000000000..ee524e91c2 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/isinteger/index.html @@ -0,0 +1,118 @@ +--- +title: Number.isInteger() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/isInteger +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isInteger +--- +<div>{{JSRef}}</div> + +<p>El mètode<strong> <code>Number.isInteger()</code></strong> determina si el valor que se li passa és un nombre sencer.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.isInteger(valor)</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor que serà comprovat si és sencer o no.</dd> +</dl> + +<h2 id="Descripció">Descripció</h2> + +<p>Si el valor passat és un nombre sencer, la funció retornarà <code>true</code>, en cas contrari es retorna <code>false</code>. Si el valor és {{jsxref("Global_Objects/NaN", "NaN")}} o infinit, es retorna <code>false</code>.</p> + +<h2 id="Exemples">Exemples</h2> + +<pre class="brush: js">Number.isInteger(0.1); // false +Number.isInteger(1); // true +Number.isInteger(Math.PI); // false +Number.isInteger(-100000); // true +Number.isInteger(NaN); // false +Number.isInteger(0); // true +Number.isInteger("10"); // 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="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isinteger', 'Number.isInteger')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("16")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile("16")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Global_Objects/Number", "Number")}} al que pertany.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/isnan/index.html b/files/ca/web/javascript/reference/global_objects/number/isnan/index.html new file mode 100644 index 0000000000..f6ba247306 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/isnan/index.html @@ -0,0 +1,129 @@ +--- +title: Number.isNaN() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/isNaN +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isNaN +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>Number.isNaN()</code></strong> determina si el valor passat com a argument és {{jsxref("Global_Objects/NaN", "NaN")}}. És una versió més robusta de la funció global {{jsxref("Global_Objects/isNaN", "isNaN()")}}.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.isNaN(valor)</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor que es comprovarà si és {{jsxref("Global_Objects/NaN", "NaN")}}.</dd> +</dl> + +<h2 id="Descripció">Descripció</h2> + +<p>Degut als dos operadors d'igualtat, {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}} i {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}, retornen <code>false</code> quan es comprova si {{jsxref("Global_Objects/NaN", "NaN")}} <em>és</em> {{jsxref("Global_Objects/NaN", "NaN")}}, la funció <code>Number.isNaN()</code> esdevé necesària. Aquesta situació és diferent a totes les altres posibles comparacions a JavaScript.</p> + +<p>En comparació a la funció global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, <code>Number.isNaN()</code> no sofreix el problema de convertir forçosament el paràmetre donat a un nombre. Això implica que ara és segur passar valors que normalment serien convertits a {{jsxref("Global_Objects/NaN", "NaN")}} però en realitat no tenen el mateix valor que {{jsxref("Global_Objects/NaN", "NaN")}}. Això també implica que només valors de tipus number, que també siguin {{jsxref("Global_Objects/NaN", "NaN")}}, retornaran <code>true</code>.</p> + +<h2 id="Exemples">Exemples</h2> + +<pre class="brush: js">Number.isNaN(NaN); // true +Number.isNaN(Number.NaN); // true +Number.isNaN(0 / 0) // true + +// exemples que esdevindrien true amb la funció global isNaN() +Number.isNaN("NaN"); // false +Number.isNaN(undefined); // false +Number.isNaN({}); // false +Number.isNaN("blabla"); // false + +// Tots els següents retornen 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">Number.isNaN = Number.isNaN || function(value) { + return typeof value === "number" && value !== value; +}</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.isnan', 'Number.isnan')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatGeckoMobile("15")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>iOS 9+</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>{{jsxref("Global_Objects/Number", "Number")}}</li> + <li>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/issafeinteger/index.html b/files/ca/web/javascript/reference/global_objects/number/issafeinteger/index.html new file mode 100644 index 0000000000..7570e7289d --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/issafeinteger/index.html @@ -0,0 +1,117 @@ +--- +title: Number.isSafeInteger() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/isSafeInteger +translation_of: Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>Number.isSafeInteger()</code></strong> determina si el valor proporcionat és un nombre sencer segur. Un nombre sencer segur és aquell que</p> + +<ul> + <li>pot ser representat de forma exacta per un nombre de doble precisió IEEE-754, i</li> + <li>la seva representació IEEE-754 no pot ser el resultat de arrodonir cap altre nombre sencer per a encabir-lo a la representació IEEE-754.</li> +</ul> + +<p>Per exemple, <code>2<sup>53</sup> - 1</code> és un nombre sencer segur: pot ser representat de forma exacta i cap altre nombre sencer arrodonit coincideix amb ell sota cap mode d'arrodoniment IEEE-754. Per contra, <code>2<sup>53</sup></code> <em>no</em> és un nombre sencer segur: pot ser representat de manera exacta en IEEE-754, però el nombre sencer <code>2<sup>53</sup> + 1</code> no pot ser representat directament en IEEE-754 sino que s'arrodoniria a <code>2<sup>53</sup></code> mitjançant un arrodoniment al sencer més proper i un arrodoniment cap al zero.</p> + +<p>Els nombres sencers segurs consisteixen en tots els nombres sencers des de <code>-(2<sup>53</sup> - 1)</code> inclòs fins a <code>2<sup>53</sup> - 1</code> inclòs.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.isSafeInteger(valor)</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>valor</code></dt> + <dd>El valor a ser testat com a nombre sencer segur.</dd> +</dl> + +<h2 id="Exemples">Exemples</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="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.issafeinteger', 'Number.isSafeInteger')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("32")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <td>Característica</td> + <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>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile("32")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Global_Objects/Number", "Number")}} al que pertany.</li> + <li>{{jsxref("Number.MIN_SAFE_INTEGER")}}</li> + <li>{{jsxref("Number.MAX_SAFE_INTEGER")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/max_safe_integer/index.html b/files/ca/web/javascript/reference/global_objects/number/max_safe_integer/index.html new file mode 100644 index 0000000000..02483b41ac --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/max_safe_integer/index.html @@ -0,0 +1,100 @@ +--- +title: Number.MAX_SAFE_INTEGER +slug: Web/JavaScript/Referencia/Objectes_globals/Number/MAX_SAFE_INTEGER +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La constant <strong><code>Number.MAX_SAFE_INTEGER</code></strong> representa el valor màxim que JavaScript pot representar de forma segura (<code>2<sup>53</sup> - 1</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>La constant <code>MAX_SAFE_INTEGER</code> te un valor de <code>9007199254740991</code>. El raonament darrera d'aquest nombre és que JavaScript utilitza un <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format">format de nombres de coma flotant de doble precisió</a>, tal com s'especifica al <a href="http://en.wikipedia.org/wiki/IEEE_floating_point">IEEE 754</a> i en conseqüència només pot representar de forma segura els nombres entre <code>-(2<sup>53</sup> - 1)</code> i <code>2<sup>53</sup> - 1</code>.</p> + +<p>Degut a que <code>MAX_SAFE_INTEGER</code> és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'accedeix de mitjançant <code>Number.MAX_SAFE_INTEGER</code> en comptes de com una propietat d'un objecte {{jsxref("Global_Objects/Number", "Number")}} instanciat.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<pre class="brush: js">Number.MAX_SAFE_INTEGER // 9007199254740991 +Math.pow(2, 53) - 1 // 9007199254740991 +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.max_safe_integer', 'Number.MAX_SAFE_INTEGER')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatChrome("34")}}</td> + <td>{{CompatGeckoDesktop("31")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("32")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.MIN_SAFE_INTEGER")}}</li> + <li>{{jsxref("Number.isSafeInteger()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/max_value/index.html b/files/ca/web/javascript/reference/global_objects/number/max_value/index.html new file mode 100644 index 0000000000..453ad01c23 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/max_value/index.html @@ -0,0 +1,118 @@ +--- +title: Number.MAX_VALUE +slug: Web/JavaScript/Referencia/Objectes_globals/Number/MAX_VALUE +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE +--- +<div> +<div>{{JSRef("Global_Objects", "Number")}}</div> +</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La propietat <strong><code>Number.MAX_VALUE</code></strong> representa el valor numèric màxim representable en JavaScript.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>La propietat <code>MAX_VALUE</code> té un valor aproximadament de <code>1.79E+308</code>. Els valors més grans que <code>MAX_VALUE</code> són representats com a "<code>Infinity</code>".</p> + +<p>Ja que <code>MAX_VALUE</code> és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre es fa servir com a <code>Number.MAX_VALUE</code>, en comptes d'una propietat de l'objecte {{jsxref("Global_Objects/Number", "Number")}} que s'ha creat.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Example:_Using_MAX_VALUE" name="Example:_Using_MAX_VALUE">Exemple: Fer servir <code>MAX_VALUE</code></h3> + +<p>El codi següent multiplica dos valors numèrics. Si el resultat és menor o igual a <code>MAX_VALUE</code>, es crida la funció <code>func1</code>; del contrari, es crida la funció <code>func2</code>.</p> + +<pre class="brush: js">if (num1 * num2 <= Number.MAX_VALUE) { + func1(); +} else { + func2(); +} +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>1a edició de ECMAScript.</td> + <td>Estàndard</td> + <td>Definició inicial. Implementat en 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> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Supor bàsic</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" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.MIN_VALUE")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/min_safe_integer/index.html b/files/ca/web/javascript/reference/global_objects/number/min_safe_integer/index.html new file mode 100644 index 0000000000..861ec666ec --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/min_safe_integer/index.html @@ -0,0 +1,100 @@ +--- +title: Number.MIN_SAFE_INTEGER +slug: Web/JavaScript/Referencia/Objectes_globals/Number/MIN_SAFE_INTEGER +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La constant <strong><code>Number.MIN_SAFE_INTEGER</code></strong> representa el nombre sencer segur més petit a JavaScript (<code>-(2<sup>53</sup> - 1)</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>La constant <code>MIN_SAFE_INTEGER</code> te un valor de<code> -9007199254740991</code>. El raonament darrera d'aquest nombre és que JavaScript utilitza un <a href="http://en.wikipedia.org/wiki/Double_precision_floating-point_format">format de nombres de coma flotant de doble precisió</a>, tal com s'especifica al <a href="http://en.wikipedia.org/wiki/IEEE_floating_point">IEEE 754</a> i en conseqüència només pot representar de forma segura els nombres entre <code>-(2<sup>53</sup> - 1)</code> i <code>2<sup>53</sup> - 1</code>.</p> + +<p>Degut a que <code>MIN_SAFE_INTEGER</code> és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'accedeix de mitjançant <code>Number.MIN_SAFE_INTEGER</code> en comptes de com una propietat d'un objecte {{jsxref("Global_Objects/Number", "Number")}} instanciat.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<pre class="brush: js">Number.MIN_SAFE_INTEGER // -9007199254740991 +-(Math.pow(2, 53) - 1) // -9007199254740991 +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.min_safe_integer', 'Number.MIN_SAFE_INTEGER')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatChrome("34")}}</td> + <td>{{CompatGeckoDesktop("31")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("32")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="See_also" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.MAX_SAFE_INTEGER")}}</li> + <li>{{jsxref("Number.isSafeInteger()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/min_value/index.html b/files/ca/web/javascript/reference/global_objects/number/min_value/index.html new file mode 100644 index 0000000000..42af185360 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/min_value/index.html @@ -0,0 +1,118 @@ +--- +title: Number.MIN_VALUE +slug: Web/JavaScript/Referencia/Objectes_globals/Number/MIN_VALUE +translation_of: Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La propietat <strong><code>Number.MIN_VALUE</code></strong> representa el valor numèric positiu més petit representable en JavaScript.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>La propietat <code>MIN_VALUE</code> és el nombre més proper a 0, però no és el nombre més negatiu que es pot representar en JavaScript.</p> + +<p><code>MIN_VALUE</code> té un valor aproximat de <code>5e-324</code>. Els valors més petits que <code>MIN_VALUE</code> ("underflow values") són convertits a 0.</p> + +<p>Ja que <code>MIN_VALUE</code> és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'usa com a <code>Number.MIN_VALUE</code>, i no com una propietat de l'objecte {{jsxref("Global_Objects/Number", "Number")}} que heu creat.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Example:_Using_MIN_VALUE" name="Example:_Using_MIN_VALUE">Exemple: Fer servir <code>MIN_VALUE</code></h3> + +<p>El codi següent divideix dos valors numèrics. Si el valor és més gran o igual a <code>MIN_VALUE</code>, la funció <code>func1</code> és crida; del contrari, es crida la funció <code>func2</code>.</p> + +<pre class="brush: js">if (num1 / num2 >= Number.MIN_VALUE) { + func1(); +} else { + func2(); +} +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>1a edició de ECMAScript.</td> + <td>Estàndard</td> + <td>Definició inicial. Implementat en 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> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característca</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Suport bàsic</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>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>Suport bàsic</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" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.MAX_VALUE")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/nan/index.html b/files/ca/web/javascript/reference/global_objects/number/nan/index.html new file mode 100644 index 0000000000..7c6f3f1440 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/nan/index.html @@ -0,0 +1,100 @@ +--- +title: Number.NaN +slug: Web/JavaScript/Referencia/Objectes_globals/Number/NaN +translation_of: Web/JavaScript/Reference/Global_Objects/Number/NaN +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La propietat <strong><code>Number.NaN</code></strong> representa Not-A-Number (quelcom que no és un nombre). Equivalent a {{jsxref("Global_Objects/NaN", "NaN")}}.</p> + +<p>No és necesari crear un objecte de tipus {{jsxref("Global_Objects/Number", "Number")}} per a accedir a aquesta propietat estàtica (utilitzeu <code>Number.NaN</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>ECMAScript 1a Edició.</td> + <td>Standard</td> + <td>Definició inicial. Implementat a JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.3.4', 'Number.NaN')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.nan', 'Number.NaN')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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" name="See_also">Vegeu també</h2> + +<ul> + <li>L'objecte global {{jsxref("Global_Objects/NaN", "NaN")}}.</li> + <li>L'objecte {{jsxref("Global_Objects/Number", "Number")}} al qual pertany.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/negative_infinity/index.html b/files/ca/web/javascript/reference/global_objects/number/negative_infinity/index.html new file mode 100644 index 0000000000..3fb4c1d150 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/negative_infinity/index.html @@ -0,0 +1,134 @@ +--- +title: Number.NEGATIVE_INFINITY +slug: Web/JavaScript/Referencia/Objectes_globals/Number/NEGATIVE_INFINITY +translation_of: Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY +--- +<div>{{JSRef("Global_Objects", "Number")}}</div> + +<h2 id="Summary" name="Summary">Resum</h2> + +<p>La propietat <strong><code>Number.NEGATIVE_INFINITY</code></strong> representa el valor infinit negatiu.</p> + +<p>No fa falta crear un objecte {{jsxref("Global_Objects/Number", "Number")}} per accedir a aquesta propietat estàtica (feu servir <code>Number.NEGATIVE_INFINITY</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description" name="Description">Descripció</h2> + +<p>El valor de <code>Number.NEGATIVE_INFINITY</code> és el mateix que el valor negatiu de la propietat de l'objecte global {{jsxref("Global_Objects/Infinity", "Infinity")}}.</p> + +<p>Aquest valor es comporta de forma una mica diferent a l<u>'infinit matemàtic:</u></p> + +<ul> + <li>Qualsevol valor positiu, incloent {{jsxref("Number.POSITIVE_INFINITY", "POSITIVE_INFINITY")}}, multiplicat per <code>NEGATIVE_INFINITY</code> és <code>NEGATIVE_INFINITY</code>.</li> + <li>Qualsevol calor negatiu, incloent <code>NEGATIVE_INFINITY</code>, multiplicat per <code>NEGATIVE_INFINITY</code> és {{jsxref("Number.POSITIVE_INFINITY", "POSITIVE_INFINITY")}}.</li> + <li>Zero multiplicat per <code>NEGATIVE_INFINITY</code> és {{jsxref("Global_Objects/NaN", "NaN")}}.</li> + <li>{{jsxref("Global_Objects/NaN", "NaN")}} multiplicat per <code>NEGATIVE_INFINITY</code> és {{jsxref("Global_Objects/NaN", "NaN")}}.</li> + <li><code>NEGATIVE_INFINITY</code>, dividit per qualsevol valor negatiu excepte <code>NEGATIVE_INFINITY</code>, és {{jsxref("Number.POSITIVE_INFINITY", "POSITIVE_INFINITY")}}.</li> + <li><code>NEGATIVE_INFINITY</code>, dividit per qualsevol valor positiu excepte {{jsxref("Number.POSITIVE_INFINITY", "POSITIVE_INFINITY")}}, és <code>NEGATIVE_INFINITY</code>.</li> + <li><code>NEGATIVE_INFINITY</code>, dividit tant per <code>NEGATIVE_INFINITY</code> com per {{jsxref("Number.POSITIVE_INFINITY", "POSITIVE_INFINITY")}}, és {{jsxref("Global_Objects/NaN", "NaN")}}.</li> + <li>Qualsevol nombre dividit per <code>NEGATIVE_INFINITY</code> és zero.</li> +</ul> + +<p>Es pot fer serivir la propietat <code>Number.NEGATIVE_INFINITY</code> per indicar una condició d'error que retorna un nombre finit en cas d'èxit. Fixeu-vos, però, que {{jsxref("Global_Objects/isFinite", "isFinite")}} seria més apropiat en aquest cas.</p> + +<h2 id="Examples" name="Examples">Exemples</h2> + +<h3 id="Exemple_Fer_servir_NEGATIVE_INFINITY">Exemple: Fer servir <code>NEGATIVE_INFINITY</code></h3> + +<p><u>En l'exemple següent, a la variable <code>smallNumber</code> se li assigna un valor que és més petit que el valor mínim. Quan la delcaració {{jsxref("Statements/if...else", "if")}} s'executa, <code>smallNumber</code> té el valor <code>-Infinity</code>, així <code>smallNumber</code> s'estableix com a un valor més manegable abans de prosseguir.</u></p> + +<pre class="brush: js notranslate">var smallNumber = (-Number.MAX_VALUE) * 2; + +if (smallNumber == Number.NEGATIVE_INFINITY) { + smallNumber = returnFinite(); +} +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>1a edició de ECMAScript.</td> + <td>Estàndard</td> + <td>Definició inicial. Implementat en JavaScript 1.1.</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="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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" name="See_also">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.POSITIVE_INFINITY")}}</li> + <li>{{jsxref("Number.isFinite()")}}</li> + <li>{{jsxref("Global_Objects/Infinity", "Infinity")}}</li> + <li>{{jsxref("Global_Objects/isFinite", "isFinite()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/parsefloat/index.html b/files/ca/web/javascript/reference/global_objects/number/parsefloat/index.html new file mode 100644 index 0000000000..cd3494b7ac --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/parsefloat/index.html @@ -0,0 +1,103 @@ +--- +title: Number.parseFloat() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/parseFloat +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseFloat +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>Number.parseFloat()</code></strong> interpreta el string passat com a argument i retorna un nombre de punt flotant. Aquest mètode es comporta de la mateixa manera que la funció global {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} i és part del ECMAScript 6 (el seu motiu d'existència és la modularització dels globals).</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.parseFloat(<var>string</var>)</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>string</code></dt> + <dd>Un string que representa el valor a interpretar.</dd> +</dl> + +<h2 id="Descripció">Descripció</h2> + +<p>Vegeu {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} per a més detalls i exemples.</p> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">Number.parseFloat = parseFloat;</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.parsefloat', 'Number.parseFloat')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</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>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Number")}} al que pertany.</li> + <li>La funció global {{jsxref("Global_Objects/parseFloat", "parseFloat()")}}.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/parseint/index.html b/files/ca/web/javascript/reference/global_objects/number/parseint/index.html new file mode 100644 index 0000000000..2ef9597d11 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/parseint/index.html @@ -0,0 +1,102 @@ +--- +title: Number.parseInt() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/parseInt +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseInt +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>Number.parseInt()</code></strong> interpreta un argument string i retorna un nombre sencer de la base especificada.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code>Number.parseInt(<var>string</var>[, <var>radix</var>])</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<div>{{page("ca/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Parameters")}}</div> + +<h2 id="Descripció">Descripció</h2> + +<p>Aquest mètode és exactament la mateixa funció que la funció global {{jsxref("Global_Objects/parseInt", "parseInt()")}}:</p> + +<pre class="brush: js">Number.parseInt === parseInt; // true</pre> + +<p>i és part de l'ECMAScript 6 (el seu propòsit és la modularització de les globals). Vegeu jsxref("Global_Objects/parseInt", "parseInt()")}} per a més detalls i exemples.</p> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: js">Number.parseInt = parseInt;</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.parseint', 'Number.parseInt')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Definició inicial.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Característica</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Suport bàsic</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoDesktop("25")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Vegeu_també">Vegeu també</h2> + +<ul> + <li>L'objecte {{jsxref("Number")}} al que pertany.</li> + <li>La funció global {{jsxref("Global_Objects/parseInt", "parseInt()")}}.</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/positive_infinity/index.html b/files/ca/web/javascript/reference/global_objects/number/positive_infinity/index.html new file mode 100644 index 0000000000..234a779fd1 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/positive_infinity/index.html @@ -0,0 +1,137 @@ +--- +title: Number.POSITIVE_INFINITY +slug: Web/JavaScript/Referencia/Objectes_globals/Number/POSITIVE_INFINITY +translation_of: Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY +--- +<div>{{JSRef}}</div> + +<p>La propietat <strong><code>Number.POSITIVE_INFINITY</code></strong> representa el valor infinit negatiu.</p> + +<p>No fa falta crear un objecte {{jsxref("Global_Objects/Number", "Number")}} per accedir a aquesta propietat estàtica (feu servir <code>Number.POSITIVE_INFINITY</code>).</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Descripció">Descripció</h2> + +<p>El valor de <code>Number.POSITIVE_INFINITY</code> és el mateix que el valor negatiu de la propietat de l'objecte global {{jsxref("Infinity")}}.</p> + +<p> </p> + +<p>Aquest valor es comporta de forma una mica diferent a l'infinit matemàtic<u>:</u></p> + +<p>Qualsevol valor positiu, incloent <code>POSITIVE_INFINITY</code>, multiplicat per <code>POSITIVE_INFINITY</code> és <code>POSITIVE_INFINITY</code>.</p> + +<ul> + <li>Qualsevol calor negatiu, incloent <code>NEGATIVE_INFINITY</code>, multiplicat per <code>POSITIVE_INFINITY</code> és {{jsxref("Number.<code>NEGATIVE</code>_INFINITY", "POSITIVE_INFINITY")}}.</li> + <li>Zero multiplicat per<code> POSITIVE_INFINITY</code> és {{jsxref("NaN")}}.</li> + <li>{{jsxref("Global_Objects/NaN", "NaN")}} multiplicat per<code>POSITIVE_INFINITY</code> és {{jsxref("NaN")}}.</li> + <li><code>POSITIVE_INFINITY</code>, dividit per quaulsevol valor negatiu execepte {{jsxref("Number.NEGATIVE_INFINITY", "NEGATIVE_INFINITY")}}, és {{jsxref("Number.NEGATIVE_INFINITY", "NEGATIVE_INFINITY")}}.</li> + <li><code>POSITIVE_INFINITY</code>, dividit per un valor positiu a excepció de<code> POSITIVE_INFINITY</code>, és <code>POSITIVE_INFINITY</code>.</li> + <li><code>POSITIVE_INFINITY</code>, dividit per {{jsxref("Number.NEGATIVE_INFINITY", "NEGATIVE_INFINITY")}} o bé per <code>POSITIVE_INFINITY</code>, és {{jsxref("NaN")}}.</li> + <li>Quasevol nombre dividit per<code> POSITIVE_INFINITY</code> és Zero.</li> +</ul> + +<p>Es pot fer serivir la propietat <code>Number.POSITIVE_INFINITY</code> per indicar una condició d'error que retorna un nombre finit en cas d'èxit. Fixeu-vos, però, que {{jsxref("isFinite")}} seria més apropiat en aquest cas.</p> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_POSITIVE_INFINITY">Utilitzar <code>POSITIVE_INFINITY</code></h3> + +<p>In the following example, the variable <code>bigNumber</code> is assigned a value that is larger than the maximum value. When the {{jsxref("Statements/if...else", "if")}} statement executes, <code>bigNumber</code> has the value <code>Infinity</code>, so <code>bigNumber</code> is set to a more manageable value before continuing.</p> + +<p>A l'exemple següent, a la variable <code>nombrePetit</code> se li assigna un valor que és més gran que el valor màxim. Quan la declaració {{jsxref("Statements/if...else", "if")}} s'executa, <code>nombrePetit</code> té el valor <code>Infinity</code>, així <code>nombrePetit</code> s'estableix com a un valor més manegable abans de prosseguir.</p> + +<pre class="brush: js">var nombrePetit = Number.MAX_VALUE * 2; + +if (nombrePetit == Number.POSITIVE_INFINITY) { + nombrePetit= returnFinite(); +} +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definició inicial. Implementat a JavaScript 1.1.</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="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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="Vegeu_també">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li> + <li>{{jsxref("Number.isFinite()")}}</li> + <li>{{jsxref("Infinity")}}</li> + <li>{{jsxref("Global_Objects/isFinite", "isFinite()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/toexponential/index.html b/files/ca/web/javascript/reference/global_objects/number/toexponential/index.html new file mode 100644 index 0000000000..69ca3478ac --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/toexponential/index.html @@ -0,0 +1,136 @@ +--- +title: Number.prototype.toExponential() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/toExponential +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toExponential +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>toExponential()</code></strong> retorna un string que representa l'objecte de tipus <code>Number</code> en notació exponencial.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>numObj</var>.toExponential([dígitsDecimals])</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>dígitsDecimals</code></dt> + <dd>Opcional. Un nombre sencer que indica el nombre de dígits decimals que s'utilitzaran. Si no s'especifica s'utilitzaran per defecte tants dígits decimals com facin falta per a acomodar el nombre.</dd> +</dl> + +<h3 id="Valor_retornat">Valor retornat</h3> + +<p>Un string que representa l'objecte {{jsxref("Number")}} en notació exponencial amb un dígit a l'esquerra del punt decimal, i arrodonit a <code>dígitsDecimals</code> després del punt decimal. Si s'omet el paràmetre <code>fractionDigits</code> s'utilitzaran tants dígits decimals com facin falta per a acomodar el nombre.</p> + +<p>Si s'utilitza el mètode <code>toExponential()</code> en un literal numèric i el literal numèric no té exponent ni punt decimal, deixeu un espai abans del punt que precedeix a la crida del mètode per a evitar que el punt s'interpreti com a punt decimal.</p> + +<p>Si un nombre té més dígits dels que s'especifiquen al paràmetre <code>dígitsDecimals</code> el nombre s'arrodoneix al nombre més proper representable pel nombre de dígits <code>dígitsDecimals</code>. Vegeu la discussió sobre arrodoniment a la descripció del mètode {{jsxref("Number.prototype.toFixed", "toFixed()")}}, que també s'aplica al mètode <code>toExponential()</code>.</p> + +<h3 id="Excepcions_llençades">Excepcions llençades</h3> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>Si el valor de <code>dígitsDecimals</code> és massa petit o massa gran. Els valors acceptats estan entre 0 i 20, ambdos inclusius, i no llençaran per tant l'excepció <a class="new" href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/RangeError" title="Aquesta pàgina encara no ha estat traduïda. Si us plau considera contribuir-hi!"><code>RangeError</code></a>. Les implementacions poden opcionalment donar suport per a valors més grans.</dd> + <dt>{{jsxref("TypeError")}}</dt> + <dd>Si es crida aquest mètode i se li passa un paràmetre que no és de tipus <a href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/Objectes_globals/Number" title="L'objecte de JavaScript Number és un objecte embolcall que permet treballar amb valors numèrics. Un objecte de tipus Number és creat quan es crida el constructor Number()."><code>Number</code></a>.</dd> +</dl> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_toExponential">Utilitzar <code>toExponential</code></h3> + +<pre class="brush: js">var numObj = 77.1234; + +console.log(numObj.toExponential()); // escriu 7.71234e+1 +console.log(numObj.toExponential(4)); // escriu 7.7123e+1 +console.log(numObj.toExponential(2)); // escriu 7.71e+1 +console.log(77.1234.toExponential()); // escriu 7.71234e+1 +console.log(77 .toExponential()); // escriu 7.7e+1 +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES3')}}</td> + <td>{{Spec2('ES3')}}</td> + <td>Definició inicial. Implementat a 1.5.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.4.6', 'Number.prototype.toExponential')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.prototype.toexponential', 'Number.prototype.toExponential')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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="Vegeu_també">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.prototype.toFixed()")}}</li> + <li>{{jsxref("Number.prototype.toPrecision()")}}</li> + <li>{{jsxref("Number.prototype.toString()")}}</li> +</ul> diff --git a/files/ca/web/javascript/reference/global_objects/number/tofixed/index.html b/files/ca/web/javascript/reference/global_objects/number/tofixed/index.html new file mode 100644 index 0000000000..8df53aafe3 --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/tofixed/index.html @@ -0,0 +1,135 @@ +--- +title: Number.prototype.toFixed() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/toFixed +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toFixed +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>toFixed()</code></strong> formateja un nombre utilitzant notació de coma fixa.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>numObj</var>.toFixed([<var>dígits</var>])</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>dígits</code></dt> + <dd>Opcional. El nombre de dígits a utilitzar després del punt decimal; aquest paràmetre pot rebre valors entre 0 i 20, ambdós inclusius, i les implementacions poden opcionalment donar suport per a valors més grans. Si s'omet aquest argument s'utilitza un valor de 0 per defecte.</dd> +</dl> + +<h3 id="Valor_retornat">Valor retornat</h3> + +<p>Una representació de <code>numObj</code> en forma de string que no utilitza notació exponencial i té exactament <code>dígits</code> digits després del punt decimal. El nombre s'arrodoneix en cas que sigui necesari, així com la part fraccionaria s'omple amb zeros en cas necesari. Si <code>numObj</code> és major que <code>1e+21</code>, aquest mètode retornarà un string en notació exponencial, proporcionat pel mètode {{jsxref("Number.prototype.toString()")}}.</p> + +<h3 id="Excepcions_llençades">Excepcions llençades</h3> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>Si el valor de <code>dígits</code> és massa petit o massa gran. Els valors acceptats estan entre 0 i 20, ambdos inclusius, i no llençaran per tant l'excepció {{jsxref("RangeError")}}. Les implementacions poden opcionalment donar suport per a valors més grans.</dd> + <dt>{{jsxref("TypeError")}}</dt> + <dd>Si es crida aquest mètode i se li passa un paràmetre que no és de tipus {{jsxref( "Number")}}.</dd> +</dl> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_toFixed">Utilitzar <code>toFixed</code></h3> + +<pre class="brush: js">var numObj = 12345.6789; + +numObj.toFixed(); // Retorna '12346': recalquem l'arrodoniment, no hi ha part decimal +numObj.toFixed(1); // Retorna '12345.7': recalquem l'arrodoniment +numObj.toFixed(6); // Retorna '12345.678900': recalquem els zeros afegits +(1.23e+20).toFixed(2); // Retorna '123000000000000000000.00' +(1.23e-10).toFixed(2); // Retorna '0.00' +2.34.toFixed(1); // Retorna '2.3' +-2.34.toFixed(1); // Retorna -2.3 (degut a la precedència d'operadors, nombres literals negatius no retornen un string...) +(-2.34).toFixed(1); // Retorna'-2.3' (...a no ser que s'utilitzin parèntesi) +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES3')}}</td> + <td>{{Spec2('ES3')}}</td> + <td>Definició inicial. Implementat a 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> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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="Vegeu_també">Vegeu també</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/ca/web/javascript/reference/global_objects/number/toprecision/index.html b/files/ca/web/javascript/reference/global_objects/number/toprecision/index.html new file mode 100644 index 0000000000..0af5875e7f --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/toprecision/index.html @@ -0,0 +1,134 @@ +--- +title: Number.prototype.toPrecision() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/toPrecision +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toPrecision +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>toPrecision()</code></strong> retorna un string que representa l'objecte {{jsxref("Number")}} amb la precisió especificada.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>numObj</var>.toPrecision([<em>precisió</em>])</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>precisió</code></dt> + <dd>Opional. Un nombre sencer que indica el nombre de dígits significatius.</dd> +</dl> + +<h3 id="Valor_retornat">Valor retornat</h3> + +<p>Un string que representa un objecte {{jsxref("Number")}} en notació de punt fix o bé en notació exponencial, arrodonit a <code>precisió</code> dígits significatius. Vegeu la discussió sobre arrodoniment a la descripció del mètode {{jsxref("Number.prototype.toFixed()")}}, que també s'aplica a <code>toPrecision()</code>.</p> + +<p>Si s'omet l'argument <code>precisió</code>, es comporta com {{jsxref("Number.prototype.toString()")}}. Si l'argument <code>precisió</code> no és un nombre sencer, aquest s'arrodoneix al nombre sencer més proper.</p> + +<h3 id="Excepcions_llençades">Excepcions llençades</h3> + +<dl> + <dt>{{jsxref("Global_Objects/RangeError", "RangeError")}}</dt> + <dd>Si el valor de precisió no està entre 1 i 100 (ambdós inclusius), es llença un <a class="new" href="https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/RangeError" title="Aquesta pàgina encara no ha estat traduïda. Si us plau considera contribuir-hi!"><code>RangeError</code></a>. Les implementacions poden opcionalment donar suport per a valors més grans o petits. ECMA-262 tan sols requereix una precisió de fins a 21 dígits significatius.</dd> +</dl> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_toPrecision">Utilitzar <code>toPrecision</code></h3> + +<pre class="brush: js">var numObj = 5.123456; + +console.log(numObj.toPrecision()); // escriu 5.123456 +console.log(numObj.toPrecision(5)); // escriu 5.1235 +console.log(numObj.toPrecision(2)); // escriu 5.1 +console.log(numObj.toPrecision(1)); // escriu 5 + +// fixeu-vos que la notació exponencial pot retornar-se en algunes circumstàncies +console.log((1234.5).toPrecision(2)); // escriu 1.2e+3 +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES3')}}</td> + <td>{{Spec2('ES3')}}</td> + <td>Definició inicial. Implementat a 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> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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="Vegeu_també">Vegeu també</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/ca/web/javascript/reference/global_objects/number/tostring/index.html b/files/ca/web/javascript/reference/global_objects/number/tostring/index.html new file mode 100644 index 0000000000..7381fc97ac --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/number/tostring/index.html @@ -0,0 +1,141 @@ +--- +title: Number.prototype.toString() +slug: Web/JavaScript/Referencia/Objectes_globals/Number/toString +translation_of: Web/JavaScript/Reference/Global_Objects/Number/toString +--- +<div>{{JSRef}}</div> + +<p>El mètode <strong><code>toString()</code></strong> retorna un string que representa l'objecte {{jsxref("Number")}} especificat.</p> + +<h2 id="Sintaxi">Sintaxi</h2> + +<pre class="syntaxbox"><code><var>objecteNum</var>.toString([</code><em>base</em><code>])</code></pre> + +<h3 id="Paràmetres">Paràmetres</h3> + +<dl> + <dt><code>base</code></dt> + <dd>Opcional. Un nombre sencer entre 2 i 36 que indica la base a utilitzar a l'hora de representar valors numèrics.</dd> +</dl> + +<h3 id="Errors_llençats">Errors llençats</h3> + +<dl> + <dt>{{jsxref("RangeError")}}</dt> + <dd>Si <code>toString()</code> rep una <code>base</code> que no estigui entre 2 i 36, es llença un {{jsxref("RangeError")}}.</dd> +</dl> + +<h2 id="Descripció">Descripció</h2> + +<p>L'objecte {{jsxref("Number")}} sobreescriu el mètode <code>toString()</code> de l'objecte {{jsxref("Object")}}; no hereta {{jsxref("Object.prototype.toString()")}}. Per a objectes {{jsxref( "Number")}}, el mètode <code>toString()</code> retorna una representació en forma de string de l'objecte, utilitzant la base especificada.</p> + +<p>El mètode <code>toString()</code> interpreta el primer argument donat, i intenta retornar una representació en forma de string tot utilitzant la base proporcionada. Per a bases majors que 10, les lletres del alfabet indiquen numerals majors que 9. Per exemple, per a nombres hexadecimals (en base 16), s'utilitzen les lletres de la <code>a</code> a la <code>f</code>.</p> + +<p>Si no s'especifica la <code>base</code>, s'utilitza 10 com a base.</p> + +<p>Si <code>objecteNum</code> és negatiu, es conserva el signe. Això s'aplica fins i tot si la base és 2; el string retornat és la representació binària positiva de <code>objecteNum</code> precedida per un signe <code>-</code>, <strong>no</strong> s'utilitza el complement a dos de <code>objecteNum</code>.</p> + +<h2 id="Exemples">Exemples</h2> + +<h3 id="Utilitzar_toString">Utilitzar <code>toString</code></h3> + +<pre class="brush: js">var count = 10; + +console.log(count.toString()); // mostra '10' +console.log((17).toString()); // mostra '17' + +var x = 6; + +console.log(x.toString(2)); // mostra '110' +console.log((254).toString(16)); // mostra 'fe' + +console.log((-10).toString(2)); // mostra '-1010' +console.log((-0xff).toString(2)); // mostra '-11111111' +</pre> + +<h2 id="Especificacions">Especificacions</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificació</th> + <th scope="col">Estat</th> + <th scope="col">Comentaris</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definició inicial. Implementat a JavaScript 1.1.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.7.4.2', 'Number.prototype.tostring')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-number.prototype.tostring', 'Number.prototype.tostring')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilitat_amb_navegadors">Compatibilitat amb navegadors</h2> + +<div>{{CompatibilityTable}}</div> + +<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>Suport bàsic</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>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>Suport bàsic</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="Vegeu_també">Vegeu també</h2> + +<ul> + <li>{{jsxref("Number.prototype.toFixed()")}}</li> + <li>{{jsxref("Number.prototype.toExponential()")}}</li> + <li>{{jsxref("Number.prototype.toPrecision()")}}</li> +</ul> |
