aboutsummaryrefslogtreecommitdiff
path: root/files/bn/web/javascript/reference/global_objects/number/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/bn/web/javascript/reference/global_objects/number/index.html')
-rw-r--r--files/bn/web/javascript/reference/global_objects/number/index.html218
1 files changed, 218 insertions, 0 deletions
diff --git a/files/bn/web/javascript/reference/global_objects/number/index.html b/files/bn/web/javascript/reference/global_objects/number/index.html
new file mode 100644
index 0000000000..a4740d7dab
--- /dev/null
+++ b/files/bn/web/javascript/reference/global_objects/number/index.html
@@ -0,0 +1,218 @@
+---
+title: Number
+slug: Web/JavaScript/Reference/Global_Objects/Number
+tags:
+ - JavaScript
+ - JavaScript Reference
+ - Number
+ - Reference
+ - Référence(2)
+translation_of: Web/JavaScript/Reference/Global_Objects/Number
+---
+<div>{{JSRef}}</div>
+
+<p>The <strong><code>Number</code></strong> JavaScript object is a wrapper object allowing you to work with numerical values. A <code>Number</code> object is created using the <code>Number()</code> constructor.</p>
+
+<h2 id="Syntax" name="Syntax">Constructor</h2>
+
+<pre class="syntaxbox">new Number(value);</pre>
+
+<h3 id="Parameters" name="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>value</code></dt>
+ <dd>The numeric value of the object being created.</dd>
+</dl>
+
+<h2 id="Description" name="Description">Description</h2>
+
+<p>The primary uses for the <code>Number</code> object are:</p>
+
+<ul>
+ <li>If the argument cannot be converted into a number, it returns {{jsxref("Global_Objects/NaN", "NaN")}}.</li>
+ <li>In a non-constructor context (i.e., without the {{jsxref("Operators/new", "new")}} operator), <code>Number</code> can be used to perform a type conversion.</li>
+</ul>
+
+<h2 id="Properties" name="Properties">Properties</h2>
+
+<dl>
+ <dt>{{jsxref("Number.EPSILON")}} {{experimental_inline}}</dt>
+ <dd>The smallest interval between two representable numbers.</dd>
+ <dt>{{jsxref("Number.MAX_SAFE_INTEGER")}} {{experimental_inline}}</dt>
+ <dd>The maximum safe integer in JavaScript (<code>2<sup>53</sup> - 1</code>).</dd>
+ <dt>{{jsxref("Number.MAX_VALUE")}}</dt>
+ <dd>The largest positive representable number.</dd>
+ <dt>{{jsxref("Number.MIN_SAFE_INTEGER")}} {{experimental_inline}}</dt>
+ <dd>The minimum safe integer in JavaScript (<code>-(2<sup>53</sup> - 1)</code>).</dd>
+ <dt>{{jsxref("Number.MIN_VALUE")}}</dt>
+ <dd>The smallest positive representable number - that is, the positive number closest to zero (without actually being zero).</dd>
+ <dt>{{jsxref("Number.NaN")}}</dt>
+ <dd>Special "not a number" value.</dd>
+ <dt>{{jsxref("Number.NEGATIVE_INFINITY")}}</dt>
+ <dd>Special value representing negative infinity; returned on overflow.</dd>
+ <dt>{{jsxref("Number.POSITIVE_INFINITY")}}</dt>
+ <dd>Special value representing infinity; returned on overflow.</dd>
+ <dt>{{jsxref("Number.prototype")}}</dt>
+ <dd>Allows the addition of properties to a <code>Number</code> object.</dd>
+</dl>
+
+<div>{{jsOverrides("Function", "properties", "MAX_VALUE", "MIN_VALUE", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY", "protoype")}}</div>
+
+<h2 id="Methods" name="Methods">Methods</h2>
+
+<dl>
+ <dt>{{jsxref("Number.isNaN()")}} {{experimental_inline}}</dt>
+ <dd>Determine whether the passed value is NaN.</dd>
+ <dt>{{jsxref("Number.isFinite()")}} {{experimental_inline}}</dt>
+ <dd>Determine whether the passed value is a finite number.</dd>
+ <dt>{{jsxref("Number.isInteger()")}} {{experimental_inline}}</dt>
+ <dd>Determine whether the passed value is an integer.</dd>
+ <dt>{{jsxref("Number.isSafeInteger()")}} {{experimental_inline}}</dt>
+ <dd>Determine whether the passed value is a safe integer (number between <code>-(2<sup>53</sup> - 1)</code> and <code>2<sup>53</sup> - 1</code>).</dd>
+ <dt><s class="obsoleteElement">{{jsxref("Number.toInteger()")}} {{obsolete_inline}}</s></dt>
+ <dd><s class="obsoleteElement">Used to evaluate the passed value and convert it to an integer (or {{jsxref("Global_Objects/Infinity", "Infinity")}}), but has been removed.</s></dd>
+ <dt>{{jsxref("Number.parseFloat()")}} {{experimental_inline}}</dt>
+ <dd>The value is the same as {{jsxref("Global_Objects/parseFloat", "parseFloat")}} of the global object.</dd>
+ <dt>{{jsxref("Number.parseInt()")}} {{experimental_inline}}</dt>
+ <dd>The value is the same as {{jsxref("Global_Objects/parseInt", "parseInt")}} of the global object.</dd>
+</dl>
+
+<div>{{jsOverrides("Function", "Methods", "isNaN")}}</div>
+
+<h2 id="Number_instances" name="Number_instances"><code>Number</code> instances</h2>
+
+<p>All <code>Number</code> instances inherit from {{jsxref("Number.prototype")}}. The prototype object of the <code>Number</code> constructor can be modified to affect all <code>Number</code> instances.</p>
+
+<h3 id="Methods_of_Number_instance" name="Methods_of_Number_instance">Methods</h3>
+
+<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/prototype', 'Methods')}}</div>
+
+<h2 id="Examples" name="Examples">Examples</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">Example: Using the <code>Number</code> object to assign values to numeric variables</h3>
+
+<p>The following example uses the <code>Number</code> object's properties to assign values to several numeric variables:</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">Example: Integer range for <code>Number</code></h3>
+
+<p>The following example shows minimum and maximum integer values that can be represented as <code>Number</code> object (for details, refer to EcmaScript standard, chapter <em>8.5 The Number Type</em>):</p>
+
+<pre class="brush: js">var biggestInt = 9007199254740992;
+var smallestInt = -9007199254740992;
+</pre>
+
+<p>When parsing data that has been serialized to JSON, integer values falling out of this range can be expected to become corrupted when JSON parser coerces them to <code>Number</code> type. Using {{jsxref("Global_Objects/String", "String")}} instead is a possible workaround.</p>
+
+<h3 id="Example:_Using_Number_to_convert_a_Date_object" name="Example:_Using_Number_to_convert_a_Date_object">Example: Using <code>Number</code> to convert a <code>Date</code> object</h3>
+
+<p>The following example converts the {{jsxref("Global_Objects/Date", "Date")}} object to a numerical value using <code>Number</code> as a function:</p>
+
+<pre class="brush: js">var d = new Date('December 17, 1995 03:24:00');
+print(Number(d));
+</pre>
+
+<p>This displays "819199440000".</p>
+
+<h3 id="Example_Convert_numeric_strings_to_numbers">Example: Convert numeric strings to numbers</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="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>ECMAScript 1st Edition.</td>
+ <td>Standard</td>
+ <td>Initial definition. Implemented in 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>New methods and properties added: ({{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="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="See_also" name="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("Global_Objects/NaN", "NaN")}}</li>
+ <li>The {{jsxref("Global_Objects/Math", "Math")}} global object</li>
+</ul>