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/tofixed/index.html | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/number/tofixed/index.html (limited to 'files/ca/web/javascript/reference/global_objects/number/tofixed') 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é

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