1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
---
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>
<p>{{Compat("javascript.builtins.Intl.NumberFormat")}}</p>
</div>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Intl")}}</li>
</ul>
|