From cb9e359a51c3249d8f5157db69d43fd413ddeda6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:45:12 +0100 Subject: unslug ca: move --- .../global_objects/number/epsilon/index.html | 102 ++++++++++ .../reference/global_objects/number/index.html | 214 +++++++++++++++++++++ .../global_objects/number/isfinite/index.html | 118 ++++++++++++ .../global_objects/number/isinteger/index.html | 118 ++++++++++++ .../global_objects/number/isnan/index.html | 129 +++++++++++++ .../global_objects/number/issafeinteger/index.html | 117 +++++++++++ .../number/max_safe_integer/index.html | 100 ++++++++++ .../global_objects/number/max_value/index.html | 118 ++++++++++++ .../number/min_safe_integer/index.html | 100 ++++++++++ .../global_objects/number/min_value/index.html | 118 ++++++++++++ .../reference/global_objects/number/nan/index.html | 100 ++++++++++ .../number/negative_infinity/index.html | 134 +++++++++++++ .../global_objects/number/parsefloat/index.html | 103 ++++++++++ .../global_objects/number/parseint/index.html | 102 ++++++++++ .../number/positive_infinity/index.html | 137 +++++++++++++ .../global_objects/number/toexponential/index.html | 136 +++++++++++++ .../global_objects/number/tofixed/index.html | 135 +++++++++++++ .../global_objects/number/toprecision/index.html | 134 +++++++++++++ .../global_objects/number/tostring/index.html | 141 ++++++++++++++ 19 files changed, 2356 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/number/epsilon/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/isfinite/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/isinteger/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/isnan/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/issafeinteger/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/max_safe_integer/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/max_value/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/min_safe_integer/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/min_value/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/nan/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/negative_infinity/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/parsefloat/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/parseint/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/positive_infinity/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/toexponential/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/tofixed/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/toprecision/index.html create mode 100644 files/ca/web/javascript/reference/global_objects/number/tostring/index.html (limited to 'files/ca/web/javascript/reference/global_objects/number') 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La propietat Number.EPSILON 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")}}.

+ +

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 Number.EPSILON per a obtindre el valor.

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

La propietat EPSILON té un valor aproximat de 2.2204460492503130808472633361816E-16, és a dir, 2-52.

+ +

Exemples

+ +

Exemple: Comprovant l'igualtat

+ +
x = 0.2;
+y = 0.3;
+equal = (Math.abs(x - y) < Number.EPSILON);
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-15.7.3.7', 'Number.EPSILON')}}{{Spec2('ES6')}}Definició inicial
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("25.0")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("25.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

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().

+ +

Constructor

+ +
new Number(valor);
+ +

Paràmetres

+ +
+
valor
+
El valor numèric de l'objecte que es pretèn crear.
+
+ +

Descripció

+ +

Els usos pricipals de l'objecte Number són:

+ + + +

Propietats

+ +
+
{{jsxref("Number.EPSILON")}} {{experimental_inline}}
+
L'interval més petit entre dos nombres que es pot representar.
+
{{jsxref("Number.MAX_SAFE_INTEGER")}} {{experimental_inline}}
+
El nombre sencer més gran que JavaScript pot representar de forma segura (253 - 1).
+
{{jsxref("Number.MAX_VALUE")}}
+
El nombre positiu més gran que pot ésser representat.
+
{{jsxref("Number.MIN_SAFE_INTEGER")}} {{experimental_inline}}
+
El nombre més petit que JavaScript pot representar de forma segura (-(253 - 1)).
+
{{jsxref("Number.MIN_VALUE")}}
+
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.
+
{{jsxref("Number.NaN")}}
+
El valor especial "not a number".
+
{{jsxref("Number.NEGATIVE_INFINITY")}}
+
El valor especial que representa l'infinit negatiu. És retornat quan es produeix un overflow.
+
{{jsxref("Number.POSITIVE_INFINITY")}}
+
El valor especial que representa l'infinit positiu. És retornat quan es produeix un overflow.
+
{{jsxref("Number.prototype")}}
+
Permet l'adició de propietats a l'objecte Number.
+
+ +
{{jsOverrides("Function", "properties", "MAX_VALUE", "MIN_VALUE", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY", "protoype")}}
+ +

Mètodes

+ +
+
{{jsxref("Number.isNaN()")}} {{experimental_inline}}
+
Determina si el valor proporcionat és NaN.
+
{{jsxref("Number.isFinite()")}} {{experimental_inline}}
+
Determina si el valor que representa és un valor finit.
+
{{jsxref("Number.isInteger()")}} {{experimental_inline}}
+
Determina si el valor que representa és un nombre i si es tracta d'un nombre sencer.
+
{{jsxref("Number.isSafeInteger()")}} {{experimental_inline}}
+
Determina si el tipus del valor proporcionat així com el valor en sí mateix és un nombre sencer segur (nombre entre -(253 - 1) i 253 - 1).
+
{{jsxref("Number.toInteger()")}} {{obsolete_inline}}
+
Utilitzat per evaluar el valor passat i convertir-lo a sencer (o bé {{jsxref("Global_Objects/Infinity", "Infinity")}}), però s'ha eliminat.
+
{{jsxref("Number.parseFloat()")}} {{experimental_inline}}
+
Fa la mateixa funció que el mètode {{jsxref("Global_Objects/parseFloat", "parseFloat")}} de l'objecte global.
+
{{jsxref("Number.parseInt()")}} {{experimental_inline}}
+
Fa la mateixa funció que el mètode {{jsxref("Global_Objects/parseInt", "parseInt")}} de l'objecte global.
+
+ +
{{jsOverrides("Function", "Methods", "isNaN")}}
+ +

Instàncies de Number

+ +

Totes les instàncies de Number hereten de {{jsxref("Number.prototype")}}. L'objecte prototype del constructor Number pot ser modificat per a afectar a totes les instàncies de Number.

+ +

Mètodes

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/prototype', 'Methods')}}
+ +

Exemples

+ +

Exemple: Utilitzar l'objecte Number per a assignar valors numèrics a variables

+ +

L'exemple que trobareu a continuació utilitza les propietats de l'objecte Number per a assignar valors a diferents variables numèriques:

+ +
var biggestNum = Number.MAX_VALUE;
+var smallestNum = Number.MIN_VALUE;
+var infiniteNum = Number.POSITIVE_INFINITY;
+var negInfiniteNum = Number.NEGATIVE_INFINITY;
+var notANum = Number.NaN;
+
+ +

Exemple: Rang de sencers de Number

+ +

El següent exemple mostra el valor sencer mínim i màxim que pot ésser representat per un objecte de tipus Number (per a més detalls, referiu-vos a l'standard EcmaScript, capítol 8.5 El tipus Number):

+ +
var biggestInt = 9007199254740992;
+var smallestInt = -9007199254740992;
+
+ +

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 Number. Una forma d'evitar aquesta limitació és utilitzar una {{jsxref("Global_Objects/String", "String")}} per representar el nombre.

+ +

Exemple: Utilitzar Number per a convertir un objecte de tipus Date

+ +

L'exemple que trobareu a continuació converteix un objecte de tipus {{jsxref("Global_Objects/Date", "Date")}} a un tipus numèric tot utilitzant Number com una funció:

+ +
var d = new Date('December 17, 1995 03:24:00');
+print(Number(d));
+
+ +

Aquest exemple mostrarà "819199440000".

+ +

Exemple: Convertir cadenes de caràcters numèriques a nombres

+ +
Number("123")     // 123
+Number("")        // 0
+Number("0x11")    // 17
+Number("0b11")    // 3
+Number("0o11")    // 9
+Number("foo")     // NaN
+Number("100a")    // NaN
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
ECMAScript 1a Edició.StandardDefinició inicial. Implementat a JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7', 'Number')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number-objects', 'Number')}}{{Spec2('ES6')}}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")}})
+ +

Compatibilitat amb navegadores

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.isFinite() determina si el valor que se li passa com a argument és un nombre finit o no.

+ +

Sintaxi

+ +
Number.isFinite(valor)
+ +

Paràmetres

+ +
+
valor
+
El valor que es comprovarà si és finit.
+
+ +

Descripció

+ +

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 true.

+ +

Exemples

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

Polyfill

+ +
Number.isFinite = Number.isFinite || function(value) {
+    return typeof value === "number" && isFinite(value);
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.isfinite', 'Number.isInteger')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("19")}}{{CompatGeckoDesktop("16")}}{{CompatNo}}{{CompatOpera("15")}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("16")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.isInteger() determina si el valor que se li passa és un nombre sencer.

+ +

Sintaxi

+ +
Number.isInteger(valor)
+ +

Paràmetres

+ +
+
valor
+
El valor que serà comprovat si és sencer o no.
+
+ +

Descripció

+ +

Si el valor passat és un nombre sencer, la funció retornarà true, en cas contrari es retorna false. Si el valor és {{jsxref("Global_Objects/NaN", "NaN")}} o infinit, es retorna false.

+ +

Exemples

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

Polyfill

+ +
Number.isInteger = Number.isInteger || function(value) {
+    return typeof value === "number" &&
+           isFinite(value) &&
+           Math.floor(value) === value;
+};
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.isinteger', 'Number.isInteger')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("16")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("16")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.isNaN() 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()")}}.

+ +

Sintaxi

+ +
Number.isNaN(valor)
+ +

Paràmetres

+ +
+
valor
+
El valor que es comprovarà si és {{jsxref("Global_Objects/NaN", "NaN")}}.
+
+ +

Descripció

+ +

Degut als dos operadors d'igualtat, {{jsxref("Operators/Comparison_Operators", "==", "#Equality")}} i {{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}, retornen  false quan es comprova si {{jsxref("Global_Objects/NaN", "NaN")}} és {{jsxref("Global_Objects/NaN", "NaN")}}, la funció Number.isNaN() esdevé necesària. Aquesta situació és diferent a totes les altres posibles comparacions a JavaScript.

+ +

En comparació a la funció global {{jsxref("Global_Objects/isNaN", "isNaN()")}} function, Number.isNaN() 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 true.

+ +

Exemples

+ +
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(" ");
+
+ +

Polyfill

+ +
Number.isNaN = Number.isNaN || function(value) {
+    return typeof value === "number" && value !== value;
+}
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.isnan', 'Number.isnan')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("25")}}{{CompatGeckoDesktop("15")}}{{CompatNo}}{{CompatVersionUnknown}}9
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatUnknown}}{{CompatGeckoMobile("15")}}{{CompatNo}}{{CompatNo}}iOS 9+
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.isSafeInteger() determina si el valor proporcionat és un nombre sencer segur. Un nombre sencer segur és aquell que

+ + + +

Per exemple, 253 - 1 é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, 253 no és un nombre sencer segur: pot ser representat de manera exacta en IEEE-754, però el nombre sencer 253 + 1 no pot ser representat directament en IEEE-754 sino que s'arrodoniria a 253 mitjançant un arrodoniment al sencer més proper i un arrodoniment cap al zero.

+ +

Els nombres sencers segurs consisteixen en tots els nombres sencers des de -(253 - 1) inclòs fins a 253 - 1 inclòs.

+ +

Sintaxi

+ +
Number.isSafeInteger(valor)
+ +

Paràmetres

+ +
+
valor
+
El valor a ser testat com a nombre sencer segur.
+
+ +

Exemples

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

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.issafeinteger', 'Number.isSafeInteger')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("32")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("32")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La constant Number.MAX_SAFE_INTEGER representa el valor màxim que JavaScript pot representar de forma segura (253 - 1).

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

La constant MAX_SAFE_INTEGER te un valor de 9007199254740991. El raonament darrera d'aquest nombre és que JavaScript utilitza un format de nombres de coma flotant de doble precisió, tal com s'especifica al IEEE 754 i en conseqüència només pot representar de forma segura els nombres entre -(253 - 1) i 253 - 1.

+ +

Degut a que MAX_SAFE_INTEGER és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'accedeix de mitjançant Number.MAX_SAFE_INTEGER en comptes de com una propietat d'un objecte {{jsxref("Global_Objects/Number", "Number")}} instanciat.

+ +

Exemples

+ +
Number.MAX_SAFE_INTEGER // 9007199254740991
+Math.pow(2, 53) - 1     // 9007199254740991
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.max_safe_integer', 'Number.MAX_SAFE_INTEGER')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("34")}}{{CompatGeckoDesktop("31")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("32")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
+
{{JSRef("Global_Objects", "Number")}}
+
+ +

Resum

+ +

La propietat Number.MAX_VALUE representa el valor numèric màxim representable en JavaScript.

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

La propietat MAX_VALUE té un valor aproximadament de 1.79E+308. Els valors més grans que MAX_VALUE són representats com a "Infinity".

+ +

Ja que MAX_VALUE és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre es fa servir com a Number.MAX_VALUE, en comptes d'una propietat de l'objecte {{jsxref("Global_Objects/Number", "Number")}} que s'ha creat.

+ +

Exemples

+ +

Exemple: Fer servir MAX_VALUE

+ +

El codi següent multiplica dos valors numèrics. Si el resultat és menor o igual a  MAX_VALUE, es crida la funció func1; del contrari, es crida la funció func2.

+ +
if (num1 * num2 <= Number.MAX_VALUE) {
+  func1();
+} else {
+  func2();
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
1a edició de ECMAScript.EstàndardDefinició inicial. Implementat en JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.3.2', 'Number.MAX_VALUE')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.max_value', 'Number.MAX_VALUE')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Supor bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La constant Number.MIN_SAFE_INTEGER representa el nombre sencer segur més petit a JavaScript (-(253 - 1)).

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

La constant MIN_SAFE_INTEGER te un valor de -9007199254740991. El raonament darrera d'aquest nombre és que JavaScript utilitza un format de nombres de coma flotant de doble precisió, tal com s'especifica al IEEE 754 i en conseqüència només pot representar de forma segura els nombres entre -(253 - 1) i 253 - 1.

+ +

Degut a que MIN_SAFE_INTEGER és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'accedeix de mitjançant Number.MIN_SAFE_INTEGER en comptes de com una propietat d'un objecte {{jsxref("Global_Objects/Number", "Number")}} instanciat.

+ +

Exemples

+ +
Number.MIN_SAFE_INTEGER // -9007199254740991
+-(Math.pow(2, 53) - 1)  // -9007199254740991
+
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.min_safe_integer', 'Number.MIN_SAFE_INTEGER')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("34")}}{{CompatGeckoDesktop("31")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("32")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La propietat Number.MIN_VALUE representa el valor numèric positiu més petit representable en JavaScript.

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

La propietat MIN_VALUE és el nombre més proper a 0, però no és el nombre més negatiu que es pot representar en JavaScript.

+ +

MIN_VALUE té un valor aproximat de 5e-324. Els valors més petits que MIN_VALUE ("underflow values") són convertits a 0.

+ +

Ja que MIN_VALUE és una propietat estàtica de {{jsxref("Global_Objects/Number", "Number")}}, sempre s'usa com a Number.MIN_VALUE, i no com una propietat de l'objecte {{jsxref("Global_Objects/Number", "Number")}} que heu creat.

+ +

Exemples

+ +

Exemple: Fer servir MIN_VALUE

+ +

El codi següent divideix dos valors numèrics. Si el valor és més gran o igual a MIN_VALUE, la funció func1 és crida; del contrari, es crida la funció func2.

+ +
if (num1 / num2 >= Number.MIN_VALUE) {
+  func1();
+} else {
+  func2();
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
1a edició de ECMAScript.EstàndardDefinició inicial. Implementat en JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.3.3', 'Number.MIN_VALUE')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.min_value', 'Number.MIN_VALUE')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterístcaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La propietat Number.NaN representa Not-A-Number (quelcom que no és un nombre). Equivalent a {{jsxref("Global_Objects/NaN", "NaN")}}.

+ +

No és necesari crear un objecte de tipus {{jsxref("Global_Objects/Number", "Number")}} per a accedir a aquesta propietat estàtica (utilitzeu Number.NaN).

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
ECMAScript 1a Edició.StandardDefinició inicial. Implementat a JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.3.4', 'Number.NaN')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.nan', 'Number.NaN')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef("Global_Objects", "Number")}}
+ +

Resum

+ +

La propietat Number.NEGATIVE_INFINITY representa el valor infinit negatiu.

+ +

No fa falta crear un objecte {{jsxref("Global_Objects/Number", "Number")}} per accedir a aquesta propietat estàtica (feu servir Number.NEGATIVE_INFINITY).

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

El valor de Number.NEGATIVE_INFINITY és el mateix que el valor negatiu de la propietat de l'objecte global {{jsxref("Global_Objects/Infinity", "Infinity")}}.

+ +

Aquest valor es comporta de forma una mica diferent a l'infinit matemàtic:

+ + + +

Es pot fer serivir la propietat Number.NEGATIVE_INFINITY 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.

+ +

Exemples

+ +

Exemple: Fer servir NEGATIVE_INFINITY

+ +

En l'exemple següent, a la variable smallNumber 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, smallNumber té el valor -Infinity, així smallNumber s'estableix com a un valor més manegable abans de prosseguir.

+ +
var smallNumber = (-Number.MAX_VALUE) * 2;
+
+if (smallNumber == Number.NEGATIVE_INFINITY) {
+  smallNumber = returnFinite();
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
1a edició de ECMAScript.EstàndardDefinició inicial. Implementat en JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.3.5', 'Number.NEGATIVE_INFINITY')}}{{Spec2('ES5.1')}}
{{SpecName('ES6', '#sec-number.negative_infinity', 'Number.NEGATIVE_INFINITY')}}{{Spec2('ES6')}}
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.parseFloat() 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).

+ +

Sintaxi

+ +
Number.parseFloat(string)
+ +

Paràmetres

+ +
+
string
+
Un string que representa el valor a interpretar.
+
+ +

Descripció

+ +

Vegeu {{jsxref("Global_Objects/parseFloat", "parseFloat()")}} per a més detalls i exemples.

+ +

Polyfill

+ +
Number.parseFloat = parseFloat;
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.parsefloat', 'Number.parseFloat')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

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

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode Number.parseInt() interpreta un argument string i retorna un nombre sencer de la base especificada.

+ +

Sintaxi

+ +
Number.parseInt(string[, radix])
+ +

Paràmetres

+ +
{{page("ca/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Parameters")}}
+ +

Descripció

+ +

Aquest mètode és exactament la mateixa funció que la funció global {{jsxref("Global_Objects/parseInt", "parseInt()")}}:

+ +
Number.parseInt === parseInt; // true
+ +

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.

+ +

Polyfill

+ +
Number.parseInt = parseInt;
+ +

Especificacions

+ + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES6', '#sec-number.parseint', 'Number.parseInt')}}{{Spec2('ES6')}}Definició inicial.
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("25")}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatNo}}{{CompatGeckoDesktop("25")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

La propietat Number.POSITIVE_INFINITY representa el valor infinit negatiu.

+ +

No fa falta crear un objecte {{jsxref("Global_Objects/Number", "Number")}} per accedir a aquesta propietat estàtica (feu servir Number.POSITIVE_INFINITY).

+ +
{{js_property_attributes(0, 0, 0)}}
+ +

Descripció

+ +

El valor de Number.POSITIVE_INFINITY és el mateix que el valor negatiu de la propietat de l'objecte global {{jsxref("Infinity")}}.

+ +

 

+ +

Aquest valor es comporta de forma una mica diferent a l'infinit matemàtic:

+ +

Qualsevol valor positiu, incloent POSITIVE_INFINITY, multiplicat per POSITIVE_INFINITY és POSITIVE_INFINITY.

+ + + +

Es pot fer serivir la propietat Number.POSITIVE_INFINITY 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.

+ +

Exemples

+ +

Utilitzar POSITIVE_INFINITY

+ +

In the following example, the variable bigNumber is assigned a value that is larger than the maximum value. When the {{jsxref("Statements/if...else", "if")}} statement executes, bigNumber has the value Infinity, so bigNumber is set to a more manageable value before continuing.

+ +

A l'exemple següent, a la variable nombrePetit 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, nombrePetit té el valor Infinity, així nombrePetit s'estableix com a un valor més manegable abans de prosseguir.

+ +
var nombrePetit = Number.MAX_VALUE * 2;
+
+if (nombrePetit == Number.POSITIVE_INFINITY) {
+  nombrePetit= returnFinite();
+}
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.3.6', 'Number.POSITIVE_INFINITY')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.positive_infinity', 'Number.POSITIVE_INFINITY')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode toExponential() retorna un string que representa l'objecte de tipus Number en notació exponencial.

+ +

Sintaxi

+ +
numObj.toExponential([dígitsDecimals])
+ +

Paràmetres

+ +
+
dígitsDecimals
+
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.
+
+ +

Valor retornat

+ +

Un string que representa l'objecte {{jsxref("Number")}} en notació exponencial amb un dígit a l'esquerra del punt decimal, i arrodonit a dígitsDecimals després del punt decimal. Si s'omet el paràmetre fractionDigits s'utilitzaran tants dígits decimals com facin falta per a acomodar el nombre.

+ +

Si s'utilitza el mètode toExponential() 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.

+ +

Si un nombre té més dígits dels que s'especifiquen al paràmetre dígitsDecimals el nombre s'arrodoneix al nombre més proper representable pel nombre de dígits dígitsDecimals. Vegeu la discussió sobre arrodoniment a la descripció del mètode {{jsxref("Number.prototype.toFixed", "toFixed()")}}, que també s'aplica al mètode toExponential().

+ +

Excepcions llençades

+ +
+
{{jsxref("RangeError")}}
+
Si el valor de dígitsDecimals és massa petit o massa gran. Els valors acceptats estan entre 0 i 20, ambdos inclusius, i no llençaran per tant l'excepció RangeError. Les implementacions poden opcionalment donar suport per a valors més grans.
+
{{jsxref("TypeError")}}
+
Si es crida aquest mètode i se li passa un paràmetre que no és de tipus Number.
+
+ +

Exemples

+ +

Utilitzar toExponential

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

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a 1.5.
{{SpecName('ES5.1', '#sec-15.7.4.6', 'Number.prototype.toExponential')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.prototype.toexponential', 'Number.prototype.toExponential')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode toFixed() formateja un nombre utilitzant notació de coma fixa.

+ +

Sintaxi

+ +
numObj.toFixed([dígits])
+ +

Paràmetres

+ +
+
dígits
+
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.
+
+ +

Valor retornat

+ +

Una representació de numObj en forma de string que no utilitza notació exponencial i té exactament dígits 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 numObj és major que 1e+21, aquest mètode retornarà un string en notació exponencial, proporcionat pel mètode {{jsxref("Number.prototype.toString()")}}.

+ +

Excepcions llençades

+ +
+
{{jsxref("RangeError")}}
+
Si el valor de dígits é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.
+
{{jsxref("TypeError")}}
+
Si es crida aquest mètode i se li passa un paràmetre que no és de tipus {{jsxref( "Number")}}.
+
+ +

Exemples

+ +

Utilitzar toFixed

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

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a JavaScript 1.5.
{{SpecName('ES5.1', '#sec-15.7.4.5', 'Number.prototype.toFixed')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.prototype.tofixed', 'Number.prototype.toFixed')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode toPrecision() retorna un string que representa l'objecte {{jsxref("Number")}} amb la precisió especificada.

+ +

Sintaxi

+ +
numObj.toPrecision([precisió])
+ +

Paràmetres

+ +
+
precisió
+
Opional. Un nombre sencer que indica el nombre de dígits significatius.
+
+ +

Valor retornat

+ +

Un string que representa un objecte {{jsxref("Number")}} en notació de punt fix o bé en notació exponencial, arrodonit a precisió dígits significatius. Vegeu la discussió sobre arrodoniment a la descripció del mètode {{jsxref("Number.prototype.toFixed()")}}, que també s'aplica a toPrecision().

+ +

Si s'omet l'argument precisió, es comporta com  {{jsxref("Number.prototype.toString()")}}. Si l'argument precisió no és un nombre sencer, aquest s'arrodoneix al nombre sencer més proper.

+ +

Excepcions llençades

+ +
+
{{jsxref("Global_Objects/RangeError", "RangeError")}}
+
Si el valor de precisió no està entre 1 i 100 (ambdós inclusius), es llença un RangeError. 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.
+
+ +

Exemples

+ +

Utilitzar toPrecision

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

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES3')}}{{Spec2('ES3')}}Definició inicial. Implementat a 1.5.
{{SpecName('ES5.1', '#sec-15.7.4.7', 'Number.prototype.toPrecision')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.prototype.toprecision', 'Number.prototype.toPrecision')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + 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 +--- +
{{JSRef}}
+ +

El mètode toString() retorna un string que representa l'objecte {{jsxref("Number")}} especificat.

+ +

Sintaxi

+ +
objecteNum.toString([base])
+ +

Paràmetres

+ +
+
base
+
Opcional. Un nombre sencer entre 2 i 36 que indica la base a utilitzar a l'hora de representar valors numèrics.
+
+ +

Errors llençats

+ +
+
{{jsxref("RangeError")}}
+
Si toString() rep una base que no estigui entre 2 i 36, es llença un {{jsxref("RangeError")}}.
+
+ +

Descripció

+ +

L'objecte {{jsxref("Number")}} sobreescriu el mètode toString() de l'objecte {{jsxref("Object")}}; no hereta {{jsxref("Object.prototype.toString()")}}. Per a objectes {{jsxref( "Number")}}, el mètode toString() retorna una representació en forma de string de l'objecte, utilitzant la base especificada.

+ +

El mètode toString() 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 a a la f.

+ +

Si no s'especifica la base, s'utilitza 10 com a base.

+ +

Si objecteNum é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 objecteNum precedida per un signe -, no s'utilitza el complement a dos de objecteNum.

+ +

Exemples

+ +

Utilitzar toString

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

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.7.4.2', 'Number.prototype.tostring')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-number.prototype.tostring', 'Number.prototype.tostring')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

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