diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/intl/numberformat | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/intl/numberformat')
6 files changed, 868 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html new file mode 100644 index 0000000000..38e1b6926c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html @@ -0,0 +1,89 @@ +--- +title: Intl.NumberFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +tags: + - Internationalization + - Intl + - JavaScript + - Method + - NumberFormat + - Prototype + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat.prototype.format()</code></strong> メソッドは、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat-prototype-format.html", "taller")}}</div> + +<p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code><var>numberFormat</var>.format(<var>number</var>)</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>number</code></dt> + <dd>整形する {{jsxref("Number")}} または {{jsxref("BigInt")}} です。</dd> +</dl> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>format</code> ゲッター関数は、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形し、文字列に格納します。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_format" name="Using_format"><code>format</code> の使用</h3> + +<p><code>format</code> ゲッター関数を使用して単一の通貨値を整形しましょう。こちらはロシアの例です。</p> + +<pre class="brush: js">var options = { style: 'currency', currency: 'RUB' }; +var numberFormat = new Intl.NumberFormat('ru-RU', options); +console.log(numberFormat.format(654321.987)); +// → "654 321,99 руб." +</pre> + +<h3 id="Using_format_with_map" name="Using_format_with_map"><code>format</code> と <code>map</code> の使用</h3> + +<p><code>format</code> ゲッター関数を使用して、配列内のすべての数値を整形することができます。なお、この関数は供給元である {{jsxref("NumberFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map")}} に渡すことができます。</p> + +<pre class="brush: js">var a = [123456.789, 987654.321, 456789.123]; +var numberFormat = new Intl.NumberFormat('es-ES'); +var formatted = a.map(numberFormat.format); +console.log(formatted.join('; ')); +// → "123.456,789; 987.654,321; 456.789,123" +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.format', 'Intl.NumberFormat.prototype.format')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.format")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> + <li>{{jsxref("Number.prototype.toLocaleString()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html new file mode 100644 index 0000000000..5d4a91fc85 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html @@ -0,0 +1,151 @@ +--- +title: Intl.NumberFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts +tags: + - Internationalization + - Intl + - JavaScript + - Method + - NumberFormat + - Prototype + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.Numberformat.prototype.formatToParts()</code></strong> メソッドは <code>NumberTimeFormat</code> フォーマッターによって生成された文字列のロケールに応じた書式設定を可能にします。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">Intl.NumberFormat.prototype.formatToParts(number)</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>number</code> {{optional_inline}}</dt> + <dd>書式化する {{jsxref("Number")}} または {{jsxref("BigInt")}}。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p>書式化された数値を含む要素のオブジェクトの {{jsxref("Array")}}。</p> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>formatToParts()</code> メソッドは、数値文字列のカスタム書式設定を行うときに便利です。ロケール固有のトークンを含むオブジェクトの {{jsxref("Array")}} を返します。その <code>formatToParts()</code> メソッドが返す構造体は、次のようになります。</p> + +<pre class="brush: js notranslate">[ + { type: "integer", value: "3" }, + { type: "group", value: "." }, + { type: "integer", value: "500" } +]</pre> + +<p>可能なタイプは以下のとおりです。</p> + +<dl> + <dt>currency</dt> + <dd>通貨の文字列です。 "$" や "€" のような記号または "Dollar", "Euro" の文字列です。これらの文字列は <code>currencyDisplay</code> の特定方法に依存します。</dd> + <dt>decimal</dt> + <dd>小数点区切り文字 (".")。</dd> + <dt>fraction</dt> + <dd>小数点以下の数値。</dd> + <dt>group</dt> + <dd>グループ区切り文字 (",")。</dd> + <dt>infinity</dt> + <dd>{{jsxref("Infinity")}} 文字列 ("∞")。</dd> + <dt>integer</dt> + <dd>整数。</dd> + <dt>literal</dt> + <dd>書式設定された数字のリテラル文字列または空白。</dd> + <dt>minusSign</dt> + <dd>マイナス記号の文字列 ("-")。</dd> + <dt>nan</dt> + <dd>{{jsxref("NaN")}} の文字列 ("NaN")。</dd> + <dt>plusSign</dt> + <dd>プラス記号の文字列 ("+")。</dd> +</dl> + +<dl> + <dt>percentSign</dt> + <dd>パーセント文字列 ("%")。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Comparing_format_and_formatToParts" name="Comparing_format_and_formatToParts">format と formatToParts の比較</h3> + +<p><code>NumberFormat</code> はローカライズされた、直接操作できない文字列を出力します。</p> + +<pre class="brush: js notranslate">var number = 3500; + +var formatter = new Intl.NumberFormat('de-DE', { + style: 'currency', + currency: 'EUR' +}); + +formatter.format(number); +// "3.500,00 €" +</pre> + +<p>しかし、多くのユーザーインターフェースでは、この文字列の書式形式をカスタマイズしたいと要望があります。 <code>formatToParts</code> メソッドは <code>NumberFormat</code> フォーマッターによって生成された文字列を要素ごとの文字列として提供することでロケールに応じた書式設定を可能にします。</p> + +<pre class="brush: js notranslate">formatter.formatToParts(number); + +// 返値: +[ + { type: "integer", value: "3" }, + { type: "group", value: "." }, + { type: "integer", value: "500" }, + { type: "decimal", value: "," }, + { type: "fraction", value: "00" }, + { type: "literal", value: " " }, + { type: "currency", value: "€" } +] +</pre> + +<p>これで情報は個別に利用可能となり、カスタマイズされた方法でフォーマットして連結することができます。例えば {{jsxref("Array.prototype.map()")}}, <a href="/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions">アロー関数</a>, <a href="/ja/docs/Web/JavaScript/Reference/Statements/switch">switch 文</a>, <a href="/ja/docs/Web/JavaScript/Reference/Template_literals">テンプレートリテラル</a>, {{jsxref("Array.prototype.reduce()")}} を使います。</p> + +<pre class="brush: js notranslate">var numberString = formatter.formatToParts(number).map(({type, value}) => { + switch (type) { + case 'currency': return `<strong>${value}</strong>`; + default : return value; + } +}).reduce((string, part) => string + part); +</pre> + +<p>上記は<code>formatToParts()</code>メソッドを使い、通貨を太字にします。</p> + +<pre class="brush: js notranslate">console.log(numberString); +// "3.500,00 <strong>€</strong>"</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.formattoparts', 'Intl.NumberFormat.prototype.formatToParts')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.formatToParts")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> + <li>{{jsxref("NumberFormat.format", "Intl.NumberFormat.prototype.format")}}</li> + <li>日付の書式化: {{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html new file mode 100644 index 0000000000..75f0c153e7 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/index.html @@ -0,0 +1,148 @@ +--- +title: Intl.NumberFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat +tags: + - Class + - Internationalization + - Intl + - JavaScript + - NumberFormat + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat</code></strong> オブジェクトは、言語に依存した数値書式を可能にするオブジェクトのコンストラクターです。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{jsxref("Intl/NumberFormat/NumberFormat", "Intl.NumberFormat()")}}</dt> + <dd>新しい <code>NumberFormat</code> オブジェクトを生成します。</dd> +</dl> + +<h2 id="Static_methods" name="Static_methods">静的メソッド</h2> + +<dl> + <dt>{{jsxref("NumberFormat.supportedLocalesOf", "Intl.NumberFormat.supportedLocalesOf()")}}</dt> + <dd>提供されたロケールのうち、実行時の既定のロケールにフォールバックせずにサポートされるものを配列に納めて返します。</dd> +</dl> + +<h2 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h2> + +<dl> + <dt>{{jsxref("NumberFormat.format", "Intl.NumberFormat.prototype.format")}}</dt> + <dd>ゲッター関数で、ローケルに応じて、この {{jsxref("NumberFormat")}} オブジェクトのオプションを持つ数値を書式化する関数を返します。</dd> + <dt>{{jsxref("NumberFormat.formatToParts", "Intl.NumberFormat.prototype.formatToParts()")}}</dt> + <dd>オブジェクトの {{jsxref("Array")}} を返し、これは専用のロケールを意識した書式で使用することができる部品内の数値文字列を表します。</dd> + <dt>{{jsxref("NumberFormat.resolvedOptions", "Intl.NumberFormat.prototype.resolvedOptions()")}}</dt> + <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_usage" name="Basic_usage">基本的な使用</h3> + +<p>ローケルを指定しない基本的な使い方では、既定のローケルとオプションで書式化された文字列が返されます。</p> + +<pre class="brush: js notranslate">var number = 3500; + +console.log(new Intl.NumberFormat().format(number)); +// → '3,500' 英語(U.S.)ロケールの場合 +</pre> + +<h3 id="locales_の使用">locales の使用</h3> + +<p>この例では、地域による数値書式の違いをいくつか紹介します。アプリケーションのユーザーインターフェイスで使われた言語書式を得るには、言語 (およびフォールバック言語) を <code>locales</code> 引数により指定してください。</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// ドイツではカンマを小数、ピリオドを千単位の区切りに用います +console.log(new Intl.NumberFormat('de-DE').format(number)); +// → 123.456,789 + +// ほとんどのアラビア語圏ではアラビア数字を用います +console.log(new Intl.NumberFormat('ar-EG').format(number)); +// → ١٢٣٤٥٦٫٧٨٩ + +// インドでは thousands/lakh/crore 区切りが用いられます +console.log(new Intl.NumberFormat('en-IN').format(number)); +// → 1,23,456.789 + +// nu 拡張キーにより漢数字などの番号方式が使えます +console.log(new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec').format(number)); +// → 一二三,四五六.七八九 + +// バリ語のようにサポートされないかもしれない言語を用いる場合は +// フォールバック言語を含めます。次の例ではインドネシア語です。 +console.log(new Intl.NumberFormat(['ban', 'id']).format(number)); +// → 123.456,789 +</pre> + +<h3 id="Using_options" name="Using_options">options の使用</h3> + +<p><code>options</code>引数を使うと結果をカスタマイズできます。</p> + +<pre class="brush: js notranslate">var number = 123456.789; + +// 通貨フォーマットを用います +console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number)); +// → 123.456,79 € + +// 日本円には小数点以下がありません +console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number)); +// → ¥123,457 + +// 有効数字を3桁に狭めます +console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number)); +// → 1,23,000 +</pre> + +<h3 id="style_と_unit_の使用">style と unit の使用</h3> + +<pre class="brush: js notranslate">console.log(new Intl.NumberFormat("pt-PT", { + style: 'unit', + unit: "mile-per-hour" +}).format(50)); +// → 50 mi/h + +console.log((16).toLocaleString('en-GB', { + style: "unit", + unit: "liter", + unitDisplay: "long" +})); +// → 16 litres +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#numberformat-objects', 'Intl.NumberFormat')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html new file mode 100644 index 0000000000..2a1932a00b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.html @@ -0,0 +1,257 @@ +--- +title: Intl.NumberFormat() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat +tags: + - Constructor + - Intl + - JavaScript + - NumberFormat + - Reference + - コンストラクター +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat +--- +<div>{{JSRef}}</div> + +<p><strong><code>Intl.NumberFormat()</code></strong> コンストラクターは、言語に依存した数値の書式を有効にするオブジェクトを生成します。</p> + +<div>{{EmbedInteractiveExample("pages/js/intl-numberformat.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate">new Intl.NumberFormat([<var>locales</var>[, <var>options</var>]]) +</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>locales</var></code> {{optional_inline}}</dt> + <dd> + <p>BCP 47 言語タグを持つ文字列、またはそのような文字列の配列。 <code><var>locales</var></code> 引数の一般的な形式と解釈については、 {{jsxref("Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。次の Unicode 拡張キーが許可されています。</p> + + <dl> + <dt><code>nu</code></dt> + <dd>使用される数値システムです。指定可能な値には "<code>adlm</code>", "<code>ahom</code>", "<code>arab</code>", "<code>arabext</code>", "<code>bali</code>", "<code>beng</code>", "<code>bhks</code>", "<code>brah</code>", "<code>cakm</code>", "<code>cham</code>", "<code>deva</code>", "<code>diak</code>", "<code>fullwide</code>", "<code>gong</code>", "<code>gonm</code>", "<code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>hmng</code>", "<code>hmnp</code>", "<code>java</code>", "<code>kali</code>", "<code>khmr</code>", "<code>knda</code>", "<code>lana</code>", "<code>lanatham</code>", "<code>laoo</code>", "<code>latn</code>", "<code>lepc</code>", "<code>limb</code>", "<code>mathbold</code>", "<code>mathdbl</code>", "<code>mathmono</code>", "<code>mathsanb</code>", "<code>mathsans</code>", "<code>mlym</code>", "<code>modi</code>", "<code>mong</code>", "<code>mroo</code>", "<code>mtei</code>", "<code>mymr</code>", "<code>mymrshan</code>", "<code>mymrtlng</code>", "<code>newa</code>", "<code>nkoo</code>", "<code>olck</code>", "<code>orya</code>", "<code>osma</code>", "<code>rohg</code>", "<code>saur</code>", "<code>segment</code>", "<code>shrd</code>", "<code>sind</code>", "<code>sinh</code>", "<code>sora</code>", "<code>sund</code>", "<code>takr</code>", "<code>talu</code>", "<code>tamldec</code>", "<code>telu</code>", "<code>thai</code>", "<code>tibt</code>", "<code>tirh</code>", "<code>vaii</code>", "<code>wara</code>", "<code>wcho</code>" があります。</dd> + </dl> + </dd> + <dt><code><var>options</var></code> {{optional_inline}}</dt> + <dd> + <p>以下のプロパティのすべてまたは一部を持つオブジェクトです。</p> + + <dl> + <dt><code>compactDisplay</code></dt> + <dd><code>notation</code> が "<code>compact</code>" の場合のみ使用されます。 "<code>short</code>" (既定値) または "<code>long</code>" のどちらかを取ります。</dd> + <dt><code>currency</code></dt> + <dd>通貨の書式で使用するための通貨です。利用可能な値は ISO 4217 通貨コードであり、例えば米ドルは "<code>USD</code>"、ユーロは "<code>EUR</code>"、日本円には "<code>JPY</code>" です。 — <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">Current currency & funds code list</a> を参照してください。既定値はありません。 <code>style</code> が "<code>currency</code>" である場合、 <code>currency</code> プロパティを提供する必要があります。</dd> + <dt><code>currencyDisplay</code></dt> + <dd>通貨の書式で通貨を表示する方法です。利用可能な値は次の通りです。 + <ul> + <li>"<code>symbol</code>" はローカライズされた通貨記号、例えば € などを使用します。これが既定値です。</li> + <li>"<code>narrowSymbol</code>" は短い形式の記号を使用します ("US$100" ではなく "$100")。</li> + <li>"<code>code</code>" は ISO 通貨コードを使用します。</li> + <li>"<code>name</code>" はローカライズされた通貨名、例えば "<code>dollar</code>" を使用します。</li> + </ul> + </dd> + <dt><code>currencySign</code></dt> + <dd>多くのロケールでは、会計の書式はマイナス記号を追加する代わりに数値を括弧で囲みます。この形式は <code>currencySign</code> オプションを "<code>accounting</code>" に設定すると有効になります。既定値は "<code>standard</code>" です。</dd> + <dt><code>localeMatcher</code></dt> + <dd>使用するロケール比較アルゴリズムです。使用可能な値は "<code>lookup</code>" および "<code>best fit</code>" です。既定値は "<code>best fit</code>" です。このオプションについての情報は、 {{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}} を参照してください。</dd> + <dt><code>notation</code></dt> + <dd>数値を表示するための書式です。既定値は "<code>standard</code>" です。 + <ul> + <li>"<code>standard</code>" 通常の数値の書式です。</li> + <li>"<code>scientific</code>" return the order-of-magnitude for formatted number.</li> + <li>"<code>engineering</code>" return the exponent of ten when divisible by three</li> + <li>"<code>compact</code>" string representing exponent, defaults is using the "short" form.</li> + </ul> + </dd> + <dt><code>numberingSystem</code></dt> + <dd>Numbering System. Possible values include: "<code>arab</code>", "<code>arabext</code>", " <code>bali</code>", "<code>beng</code>", "<code>deva</code>", "<code>fullwide</code>", " <code>gujr</code>", "<code>guru</code>", "<code>hanidec</code>", "<code>khmr</code>", " <code>knda</code>", "<code>laoo</code>", "<code>latn</code>", "<code>limb</code>", "<code>mlym</code>", " <code>mong</code>", "<code>mymr</code>", "<code>orya</code>", "<code>tamldec</code>", " <code>telu</code>", "<code>thai</code>", "<code>tibt</code>".</dd> + <dt><code>signDisplay</code></dt> + <dd>When to display the sign for the number; defaults to "<code>auto</code>" + <ul> + <li>"<code>auto</code>" sign display for negative numbers only</li> + <li>"<code>never</code>" never display sign</li> + <li>"<code>always</code>" always display sign</li> + <li>"<code>exceptZero</code>" sign display for positive and negative numbers, but not zero</li> + </ul> + </dd> + <dt><code>style</code></dt> + <dd>The formatting style to use , the default is "<code>decimal</code>". + <ul> + <li>"<code>decimal</code>" for plain number formatting.</li> + <li>"<code>currency</code>" for currency formatting.</li> + <li>"<code>percent</code>" for percent formatting</li> + <li>"<code>unit</code>" for unit formatting</li> + </ul> + </dd> + <dt><code>unit</code></dt> + <dd>The unit to use in <code>unit</code> formatting, Possible values are core unit identifiers, defined in <a href="http://unicode.org/reports/tr35/tr35-general.html#Unit_Elements" rel="nofollow">UTS #35, Part 2, Section 6</a>. A <a href="https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier" rel="nofollow">subset</a> of units from the <a href="https://github.com/unicode-org/cldr/blob/master/common/validity/unit.xml">full list</a> was selected for use in ECMAScript. Pairs of simple units can be concatenated with "<code>-per-</code>" to make a compound unit. There is no default value; if the <code>style</code> is "<code>unit</code>", the <code>unit</code> property must be provided.</dd> + <dt><code>unitDisplay</code></dt> + <dd>The unit formatting style to use in <code>unit</code> formatting, the defaults is "<code>short</code>". + <ul> + <li>"<code>long</code>" (e.g., <code>16 litres</code>)</li> + <li>"<code>short</code>" (e.g., <code>16 l</code>)</li> + <li>"<code>narrow</code>" (e.g., <code>16l</code>)</li> + </ul> + </dd> + <dt><code>useGrouping</code></dt> + <dd>Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are true and false; the default is true.</dd> + </dl> + </dd> + <dd> + <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 <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">ISO 4217 currency code list</a> (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 <a href="http://www.currency-iso.org/en/home/tables/table-a1.html">ISO 4217 currency code list</a> (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 21.</dd> + </dl> + </dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_usage">Basic usage</h3> + +<p>In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.</p> + +<pre class="brush: js notranslate">let amount = 3500; + +console.log(new Intl.NumberFormat().format(amount)); +// → '3,500' if in US English locale</pre> + +<h3 id="Decimal_and_percent_formatting">Decimal and percent formatting</h3> + +<pre class="brush: js notranslate">let amount = 3500; + +new Intl.NumberFormat('en-US', {style: 'decimal'}).format(amount); +// → '3,500' +new Intl.NumberFormat('en-US', {style: 'percent'}).format(amount); +// → '350,000%' +</pre> + +<h3 id="Unit_formatting">Unit formatting</h3> + +<p>If the <code>style</code> is <code>'unit'</code>, a <code>unit</code> property must be provided. Optionally, <code>unitDisplay</code> controls the unit formatting.</p> + +<pre class="brush: js notranslate">let amount = 3500; + +new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter'}).format(amount); +// → '3,500 L' + +new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter', unitDisplay: 'long'}).format(amount); +// → '3,500 liters' +</pre> + +<h3 id="Currency_formatting">Currency formatting</h3> + +<p>If the <code>style</code> is <code>'currency'</code>, a <code>currency</code> property must be provided. Optionally, <code>currencyDisplay</code> and <code>currencySign</code> control the unit formatting.</p> + +<pre class="brush: js notranslate">let amount = -3500; +new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount); +// → '-$3,500.00' + +new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencyDisplay: 'name' +}).format(amount); +// → '-3,500.00 US dollars' + +new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencySign: 'accounting' +}).format(amount); +// → '($3,500.00)' +</pre> + +<h3 id="Scientific_engineering_or_compact_notations">Scientific, engineering or compact notations</h3> + +<p>Scientific and compact notation are represented by the <code>notation</code> option and can be formatted like this:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat('en-US', { notation: "scientific" }).format(987654321); +// → 9.877E8 + +new Intl.NumberFormat('pt-PT', { notation: "scientific" }).format(987654321); +// → 9,877E8 + +new Intl.NumberFormat('en-GB', { notation: "engineering" }).format(987654321); +// → 987.654E6 + +new Intl.NumberFormat('de', { notation: "engineering" }).format(987654321); +// → 987,654E6 + +new Intl.NumberFormat('zh-CN', { notation: "compact" }).format(987654321); +// → 9.9亿 + +new Intl.NumberFormat('fr', { + notation: "compact", + compactDisplay: "long" +}).format(987654321); +// → 988 millions + +new Intl.NumberFormat('en-GB', { + notation: "compact", + compactDisplay: "short" +}).format(987654321); +// → 988M</pre> + +<h3 id="Displaying_signs">Displaying signs</h3> + +<p>Display a sign for positive and negative numbers, but not zero:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat("en-US", { + style: "percent", + signDisplay: "exceptZero" +}).format(0.55); +// → '+55%'</pre> + +<p>Note that when the currency sign is "accounting", parentheses might be used instead of a minus sign:</p> + +<pre class="brush: js notranslate">new Intl.NumberFormat('bn', { + style: 'currency', + currency: 'USD', + currencySign: 'accounting', + signDisplay: 'always' +}).format(-3500); + +// → '($3,500.00)'</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ES Int Draft', '#sec-intl-numberformat-constructor', 'Intl.NumberFormat constructor')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.NumberFormat")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Intl")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html new file mode 100644 index 0000000000..e32c959169 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.html @@ -0,0 +1,139 @@ +--- +title: Intl.NumberFormat.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions +tags: + - Internationalization + - JavaScript + - Method + - NumberFormat + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions +--- +<div>{{JSRef}}</div> + +<p>ローケルを反映しているプロパティとこの{{jsxref("Global_Objects/NumberFormat", "NumberFormat")}}オブジェクトの初期化中に計算された数値変換オプションをもった新しいオブジェクトを返します。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox"><code><var>numberFormat</var>.resolvedOptions()</code></pre> + +<h2 id="説明">説明</h2> + +<p>ローケルを反映しているプロパティとこの{{jsxref("Global_Objects/NumberFormat", "NumberFormat")}}オブジェクトの初期化中に計算された数値変換オプションをもった新しいオブジェクトを返します。オブジェクトは次のプロパティを持っています。:</p> + +<dl> + <dt><code>locale</code></dt> + <dd>実際に使われているローケルに対するBCP47言語タグ。Unicode表現値が入力BCP47言語タグでリクエストされたら、このローケルに対してリクエストされサポートされているキー/バリューペアは<code>locale</code>に含まれます。</dd> + <dt><code>numberingSystem</code></dt> + <dd>Unicode表現キー<code>"nu"</code>を使うかデフォルトとして設定される値。</dd> + <dt><code>style</code></dt> + <dt><code>useGrouping</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。</dd> + <dt><code>currency</code></dt> + <dt><code>currencyDisplay</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。<code>style</code>が<code>"currency"</code>の場合のみ、これらのプロパティは存在しています。</dd> +</dl> + +<p>次の2つのプロパティのグループのうちどちらかのみが含まれています。:</p> + +<dl> + <dt><code>minimumIntegerDigits</code></dt> + <dt><code>minimumFractionDigits</code></dt> + <dt><code>maximumFractionDigits</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。<code>minimumSignificantDigits</code>または<code>maximumSignificantDigits</code>が<code>options</code>引数で提供されなかった場合のみ、これらのプロパティは存在しています。</dd> + <dt><code>minimumSignificantDigits</code></dt> + <dt><code>maximumSignificantDigits</code></dt> + <dd><code>options</code>引数でプロパティに対して提供されるかデフォルトとして設定される値。 これらのプロパティのうち少なくとも1つが<code>options</code>引数で提供された場合のみ、これらのプロパティは存在しています。</dd> +</dl> + +<h2 id="例">例</h2> + +<h3 id="resolvedOptions_メソッドを使う"><code>resolvedOptions</code> メソッドを使う</h3> + +<pre class="brush: js">var de = new Intl.NumberFormat('de-DE'); +var usedOptions = de.resolvedOptions(); + +usedOptions.locale; // "de-DE" +usedOptions.numberingSystem; // "latn" +usedOption.style; // "decimal" +usedOptions.minimumIntegerDigits; // 1 +usedOptions.minimumFractionDigits; // 0 +usedOptions.maximumFractionDigits; // 3 +usedOptions.useGrouping; // true +</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-11.3.3', 'Intl.NumberFormat.prototype.resolvedOptions')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatChrome("24")}}</td> + <td>{{CompatGeckoDesktop("29")}}</td> + <td>{{CompatIE("11")}}</td> + <td>{{CompatOpera("15")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>機能</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本サポート</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome("26")}}</td> + <td>{{CompatNo}}<br> + {{bug("864843")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> +</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html new file mode 100644 index 0000000000..8108241d0b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.html @@ -0,0 +1,84 @@ +--- +title: Intl.NumberFormat.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/supportedLocalesOf +tags: + - Internationalization + - JavaScript + - Method + - NumberFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/supportedLocalesOf +--- +<div>{{JSRef("Global_Objects", "NumberFormat", "Intl,Collator,DateTimeFormat")}}</div> + +<h2 id="概要">概要</h2> + +<p>ランタイムのデフォルトローケルに戻る必要なしで数値変換でサポートされる提供されたローケルを含んでいる配列を返します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><code>Intl.NumberFormat.supportedLocalesOf(<var>locales</var>[, <var>options</var>])</code></pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code>locales</code></dt> + <dd>BCP47言語タグをもった文字列、そのような文字列の配列。<code>locales</code>引数の一般的な形式に対して、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_identification_and_negotiation", 1)}}を確認して下さい。</dd> + <dt><code>options</code></dt> + <dd> + <p>任意。次のプロパティを持つオブジェクト:</p> + + <dl> + <dt><code>localeMatcher</code></dt> + <dd>使用するローケルマッチングアルゴリズム。利用可能な値は<code>"lookup"</code> や <code>"best fit"</code>です。デフォルトは<code>"best fit"</code>です。このオプションについての情報のために、{{jsxref("Global_Objects/Intl", "Intl page", "#Locale_negotiation", 1)}}を確認して下さい。</dd> + </dl> + </dd> +</dl> + +<h2 id="説明">説明</h2> + +<p><code>locales</code>で提供された言語パックのサブセットをもった配列を返します。返される言語タグでは、ランタイムが使われているローケルマッチングアルゴリズムが考慮して数値変換でローケルをサポートしているので、デフォルトローケルに戻る必要はありません。</p> + +<h2 id="例">例</h2> + +<h3 id="例_supportedLocalesOfを使う">例: <code>supportedLocalesOf</code>を使う</h3> + +<p>数値フォーマットで、バリ語ではなく、インドネシア語とドイツ語をサポートしているランタイムを仮定すると、<code>supportedLocalesOf</code> はインドネシア語とドイツ語の言語タグを返します。<code>pinyin</code> は数値フォーマットには適切ではなくインドネシア語では使われていません。インドネシアの特定のドイツ語はサポートされそうにもありません。<code>"lookup"</code>アルゴリズムの指定に注意して下さい。<code>"best fit"</code> はインドネシア語はバリ語に対して、十分にふさわしいと決定するかもしれません。というのも、 ほとんどのバリの人はインドネシア語も理解するからです。それゆえバリ言語タグも同様に返します。</p> + +<pre class="brush: js">var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +var options = { localeMatcher: 'lookup' }; +console.log(Intl.NumberFormat.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('ES Int 1.0', '#sec-11.2.2', 'Intl.NumberFormat.supportedLocalesOf')}}</td> + <td>{{Spec2('ES Int 1.0')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> + +<div> +<div> + + +<p>{{Compat("javascript.builtins.Intl.NumberFormat.supportedLocalesOf")}}</p> +</div> +</div> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li>{{jsxref("NumberFormat", "Intl.NumberFormat")}}</li> +</ul> |