From 9b89a14666aa9a6770727ad8a2c198a10db4a7dd Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Tue, 25 Jan 2022 01:08:15 +0900 Subject: Intl.NumberFormat.prototype.format() を移行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intl/numberformat/format/index.html | 87 ---------------------- .../intl/numberformat/format/index.md | 85 +++++++++++++++++++++ 2 files changed, 85 insertions(+), 87 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.md (limited to 'files/ja/web/javascript/reference/global_objects') 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 deleted file mode 100644 index 8811aad766..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.html +++ /dev/null @@ -1,87 +0,0 @@ ---- -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 ---- -
{{JSRef}}
- -

Intl.NumberFormat.prototype.format() メソッドは、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形します。

- -
{{EmbedInteractiveExample("pages/js/intl-numberformat-prototype-format.html", "taller")}}
- - - -

構文

- -
numberFormat.format(number)
- -

引数

- -
-
number
-
整形する {{jsxref("Number")}} または {{jsxref("BigInt")}} です。
-
- -

解説

- -

format ゲッター関数は、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形し、文字列に格納します。

- -

- -

format の使用

- -

format ゲッター関数を使用して単一の通貨値を整形しましょう。こちらはロシアの例です。

- -
var options = { style: 'currency', currency: 'RUB' };
-var numberFormat = new Intl.NumberFormat('ru-RU', options);
-console.log(numberFormat.format(654321.987));
-// → "654 321,99 руб."
-
- -

formatmap の使用

- -

format ゲッター関数を使用して、配列内のすべての数値を整形することができます。なお、この関数は供給元である {{jsxref("NumberFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map")}} に渡すことができます。

- -
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"
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.format', 'Intl.NumberFormat.prototype.format')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.NumberFormat.format")}}

-
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.md b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.md new file mode 100644 index 0000000000..c277a27eee --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/numberformat/format/index.md @@ -0,0 +1,85 @@ +--- +title: Intl.NumberFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +tags: + - Internationalization + - Intl + - JavaScript + - メソッド + - NumberFormat + - プロトタイプ + - メソッド + - 国際化 +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format +--- +{{JSRef}} + +`Intl.NumberFormat.prototype.format()` メソッドは、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形します。 + +{{EmbedInteractiveExample("pages/js/intl-numberformat-prototype-format.html", "taller")}} + + + +

構文

+ +
`numberFormat.format(number)`
+ +

引数

+ +
`number`
+
整形する {{jsxref("Number")}} または {{jsxref("BigInt")}} です。
+ +## 解説 + +`format` ゲッター関数は、この {{jsxref("NumberFormat")}} オブジェクトのロケールと整形オプションに従って数値を整形し、文字列に格納します。 + +

+ +

`format` の使用

+ +`format` ゲッター関数を使用して単一の通貨値を整形しましょう。こちらはロシアの例です。 + +
var options = { style: 'currency', currency: 'RUB' };
+var numberFormat = new Intl.NumberFormat('ru-RU', options);
+console.log(numberFormat.format(654321.987));
+// → "654 321,99 руб."
+
+ +

`format` と `map` の使用

+ +`format` ゲッター関数を使用して、配列内のすべての数値を整形することができます。なお、この関数は供給元である {{jsxref("NumberFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map")}} に渡すことができます。 + +
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"
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ES Int Draft', '#sec-intl.numberformat.prototype.format', 'Intl.NumberFormat.prototype.format')}}
+ +

ブラウザーの互換性

+ +
+{{Compat("javascript.builtins.Intl.NumberFormat.format")}} +
+ +## 関連情報 + + -- cgit v1.2.3-54-g00ecf