Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 375135 of Intl.NumberFormat

  • Revision slug: JavaScript/Reference/Global_Objects/NumberFormat
  • Revision title: Intl.NumberFormat
  • Revision id: 375135
  • Created:
  • Creator: Norbert
  • Is current revision? No
  • Comment

Revision Content

Summary

The Intl.NumberFormat object is a constructor for objects that enable language sensitive number formatting.

Property of Intl
ECMAScript Edition ECMAScript Internationalization API Specification, 1st Edition

Syntax

new Intl.NumberFormat([locales [, options]])

Intl.NumberFormat.call(this [, locales [, options]])

Parameters

locales

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see the Intl page. The following Unicode extension key is allowed:

nu
The numbering system to be used. Possible values include: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt".
options

An object with some or all of the following properties:

localeMatcher
The locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see the Intl page.
style
The formatting style to use. Possible values are "decimal" for plain number formatting, "currency" for currency formatting, and "percent" for percent formatting; the default is "decimal".
currency
The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. There is no default value; if the style is "currency", the currency property must be provided.
currencyDisplay
How to display the currency in currency formatting. Possible values are "symbol" to use a localized currency symbol such as €, "code" to use the ISO currency code, "name" to use a localized currency name such as "dollar"; the default is "symbol".
useGrouping
Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are true and false; the default is true.

The following properties fall into two groups: minimumIntegerDigits, minimumFractionDigits, and maximumFractionDigits in one group, minimumSignificantDigits and maximumSignificantDigits in the other. If at least one property from the second group is defined, then the first group is ignored.

minimumIntegerDigits
The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.
minimumFractionDigits
The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information).
maximumFractionDigits
The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information); the default for percent formatting is the larger of minimumFractionDigits and 0.
minimumSignificantDigits
The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
maximumSignificantDigits
The maximum number of significant digits to use. Possible values are from 1 to 21; the default is minimumSignificantDigits.

Description

Properties

{{Js_see_prototype("NumberFormat", "Properties")}}

prototype
Allows the addition of properties to all objects.

{{jsOverrides("Function", "Properties", "prototype")}}

Methods

{{Js_see_prototype("NumberFormat", "Methods")}}

supportedLocalesOf
Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

{{jsOverrides("Function", "Methods")}}

NumberFormat instances

Properties

NumberFormat instances inherit the following properties from their prototype:

{{page('en-US/docs/JavaScript/Reference/Global_Objects/NumberFormat/prototype','Properties')}}

Methods

NumberFormat instances inherit the following methods from their prototype:

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

Examples

Browser compatibility

{{page('en-US/docs/JavaScript/Reference/Global_Objects/Intl','Browser_Compatibility')}}

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <code>Intl.NumberFormat</code> object is a constructor for objects that enable language sensitive number formatting.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Property of <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Intl" title="JavaScript/Reference/Global_Objects/Intl"><code>Intl</code></a></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ECMAScript Edition</td>
      <td>ECMAScript Internationalization API Specification, 1<sup>st</sup> Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
new Intl.NumberFormat([<em>locales</em> [, <em>options</em>]])

Intl.<code>NumberFormat</code>.call(<em>this</em> [, <em>locales</em> [, <em>options</em>]])</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
  <dt>
    <code>locales</code></dt>
  <dd>
    <p>A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the <code>locales</code> argument, see the <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Intl#Functionality_common_to_internationalization_constructors" title="/Intl#Functionality_common_to_internationalization_constructors">Intl page</a>. The following Unicode extension key is allowed:</p>
    <dl>
      <dt>
        nu</dt>
      <dd>
        The numbering system to be used. Possible values include: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt".</dd>
    </dl>
  </dd>
  <dt>
    <code>options</code></dt>
  <dd>
    <p>An object with some or all of the following properties:</p>
    <dl>
      <dt>
        <code>localeMatcher</code></dt>
      <dd>
        The locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see the <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation" title="/en-US/docs/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation">Intl page</a>.</dd>
      <dt>
        <code>style</code></dt>
      <dd>
        The formatting style to use. Possible values are "decimal" for plain number formatting, "currency" for currency formatting, and "percent" for percent formatting; the default is "decimal".</dd>
      <dt>
        <code>currency</code></dt>
      <dd>
        The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. There is no default value; if the <code>style</code> is "currency", the <code>currency</code> property must be provided.</dd>
      <dt>
        <code>currencyDisplay</code></dt>
      <dd>
        How to display the currency in currency formatting. Possible values are "symbol" to use a localized currency symbol such as €, "code" to use the ISO currency code, "name" to use a localized currency name such as "dollar"; the default is "symbol".</dd>
      <dt>
        <code>useGrouping</code></dt>
      <dd>
        Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are <code>true</code> and <code>false</code>; the default is <code>true</code>.</dd>
    </dl>
    <p>The following properties fall into two groups: <code>minimumIntegerDigits</code>, <code>minimumFractionDigits</code>, and <code>maximumFractionDigits</code> in one group, <code>minimumSignificantDigits</code> and <code>maximumSignificantDigits</code> in the other. If at least one property from the second group is defined, then the first group is ignored.</p>
    <dl>
      <dt>
        <code>minimumIntegerDigits</code></dt>
      <dd>
        The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.</dd>
      <dt>
        <code>minimumFractionDigits</code></dt>
      <dd>
        The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information).</dd>
      <dt>
        <code>maximumFractionDigits</code></dt>
      <dd>
        The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of <code>minimumFractionDigits</code> and 3; the default for currency formatting is the larger of <code>minimumFractionDigits</code> and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information); the default for percent formatting is the larger of <code>minimumFractionDigits</code> and 0.</dd>
      <dt>
        <code>minimumSignificantDigits</code></dt>
      <dd>
        The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.</dd>
      <dt>
        <code>maximumSignificantDigits</code></dt>
      <dd>
        The maximum number of significant digits to use. Possible values are from 1 to 21; the default is <code>minimumSignificantDigits</code>.</dd>
    </dl>
  </dd>
</dl>
<h2 id="Description" name="Description">Description</h2>
<h3 id="Properties" name="Properties">Properties</h3>
<p>{{Js_see_prototype("NumberFormat", "Properties")}}</p>
<dl>
  <dt>
    <a href="/en-US/docs/JavaScript/Reference/Global_Objects/NumberFormat/prototype" title="JavaScript/Reference/Global_Objects/NumberFormat/prototype">prototype</a></dt>
  <dd>
    Allows the addition of properties to all objects.</dd>
</dl>
<p>{{jsOverrides("Function", "Properties", "prototype")}}</p>
<h3 id="Methods">Methods</h3>
<p>{{Js_see_prototype("NumberFormat", "Methods")}}</p>
<dl>
  <dt>
    <a href="/en-US/docs/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf" title="JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf">supportedLocalesOf</a></dt>
  <dd>
    Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.</dd>
</dl>
<p>{{jsOverrides("Function", "Methods")}}</p>
<h2 id="NumberFormat_instances"><code>NumberFormat</code> instances</h2>
<h3 id="Properties">Properties</h3>
<p><code>NumberFormat</code> instances inherit the following properties from their prototype:</p>
<div>
  {{page('en-US/docs/JavaScript/Reference/Global_Objects/NumberFormat/prototype','Properties')}}</div>
<h3 id="Methods">Methods</h3>
<div>
  <p><code>NumberFormat</code> instances inherit the following methods from their prototype:</p>
  {{page('en-US/docs/JavaScript/Reference/Global_Objects/NumberFormat/prototype','Methods')}}</div>
<h2 id="Examples">Examples</h2>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
  {{page('en-US/docs/JavaScript/Reference/Global_Objects/Intl','Browser_Compatibility')}}</div>
Revert to this revision