aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/javascript/reference/global_objects/number/toexponential
diff options
context:
space:
mode:
Diffstat (limited to 'files/ca/web/javascript/reference/global_objects/number/toexponential')
-rw-r--r--files/ca/web/javascript/reference/global_objects/number/toexponential/index.html136
1 files changed, 136 insertions, 0 deletions
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>