# General Translation Platform: formatCurrency URL: https://generaltranslation.com/ja/docs/platform/core/reference/utility-functions/formatting/format-currency.mdx --- title: formatCurrency description: GT インスタンスを使わずに、ロケールごとに通貨値を整形します。formatCurrency の API リファレンス。 --- [`formatCurrency`](/docs/platform/core/reference/gt-class-methods/formatting/format-currency) は、General Translation のコアライブラリに含まれる単体で使えるユーティリティ関数で、数値をロケールに応じたローカライズされた通貨文字列として整形します。通貨スタイルを指定した組み込みの `Intl.NumberFormat` API をラップしたものです。 ## 概要 [#overview] `generaltranslation` から `formatCurrency` を直接インポートし、値、通貨コード、options object を指定して呼び出します。API Key や [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスは不要です。インスタンスのロケールを引き継いで書式設定する場合は、代わりに [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの [`formatCurrency`](/docs/platform/core/reference/gt-class-methods/formatting/format-currency) メソッドを使用してください。 ```typescript import { formatCurrency } from 'generaltranslation'; const price = formatCurrency(1234.56, 'EUR', { locales: ['de-DE'] }); // "1.234,56 €" ``` シグネチャ: ```typescript formatCurrency( value: number, currency: string, options?: { locales?: string | string[] } & Intl.NumberFormatOptions ): string ``` ## 動作の仕組み [#how-it-works] * **基盤となる API。** GT class method と同様に、`style: 'currency'` を指定した [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) を使用します。 * **ロケールの決定。** `locales` を省略すると、ライブラリのデフォルトロケールである `en` が使用されます。 * **記号の配置。** 通貨記号、桁区切り記号、小数の形式は、決定されたロケールに従います。 ## パラメーター [#parameters] | パラメーター | 説明 | 型 | 任意 | デフォルト | | ----------------------- | ----------------------------------- | ------------------------------------------------------------- | --- | ----- | | [`value`](#value) | フォーマットする数値です。 | `number` | いいえ | — | | [`currency`](#currency) | `USD` や `EUR` などの ISO 4217 通貨コードです。 | `string` | いいえ | — | | [`options`](#options) | 対象のロケールを含むフォーマットオプションです。 | `{ locales?: string \| string[] } & Intl.NumberFormatOptions` | はい | `{}` | ### `value` [#value] **型** `number` · **必須** フォーマットする数値。 ### `currency` [#currency] **Type** `string` · **必須** `USD`、`EUR`、`JPY` などの ISO 4217 の通貨コード。 ### `options` [#options] **Type** `{ locales?: string | string[] } & Intl.NumberFormatOptions` · **任意** · **デフォルト** `{}` 書式設定オプション: | Property | Description | Type | Optional | Default | | --------- | ------------------------- | -------------------- | -------- | ------------ | | `locales` | 書式設定に使用するロケール。 | `string \| string[]` | はい | `en` | | `style` | 数値の書式設定スタイル。デフォルトは通貨形式です。 | `string` | はい | `'currency'` | ## 戻り値 [#returns] **型** `string` ローカライズされた通貨文字列としてフォーマットされた値。 ## 例 [#examples] ```typescript import { formatCurrency } from 'generaltranslation'; // 米ドル console.log(formatCurrency(1234.56, 'USD', { locales: 'en-US' })); // Output: "$1,234.56" // ユーロ、ドイツロケール console.log(formatCurrency(1234.56, 'EUR', { locales: 'de-DE' })); // Output: "1.234,56 €" // 日本円(小数点以下なし) console.log(formatCurrency(1234, 'JPY', { locales: 'ja-JP' })); // Output: "¥1,234" ``` ## メモ [#notes] * 正確で一貫した出力を得るため、必ず `locales` に明示的な値を渡してください。 * 出力を細かく調整するには、`locales` とあわせて任意の `Intl.NumberFormatOptions` (たとえば `minimumFractionDigits`) を渡してください。