# General Translation Platform: formatCurrency URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/formatting/format-currency.mdx --- title: formatCurrency description: GT インスタンスでロケールに応じて通貨の値を整形します。formatCurrency の API リファレンス。 --- [GT](/docs/platform/core/reference/gt-class/constructor) インスタンスで、数値をローカライズされた通貨文字列として整形します。General Translation は、通貨スタイルを指定した組み込みの `Intl.NumberFormat` API を使用しているため、金額は各ロケールに応じた適切な記号、桁区切り、小数点の表記で表示されます。 ## 概要 [#overview] [`GT`](/docs/platform/core/reference/gt-class/constructor) インスタンスの `formatCurrency` に、数値、通貨コード、および任意のオプションオブジェクトを渡して呼び出します。整形された通貨文字列が返されます。 ```typescript const gt = new GT({ targetLocale: 'en-US' }); const price = gt.formatCurrency(1234.56, 'USD'); // "$1,234.56" ``` シグネチャ: ```typescript formatCurrency( value: number, currency: string, options?: { locales?: string | string[] } & Intl.NumberFormatOptions ): string ``` *注: `formatCurrency` は `Intl.NumberFormat` を使ってローカルで実行されるため、API キーは不要です。デフォルトではインスタンスの対象ロケール向けにフォーマットされ、対象ロケールが使えない場合はソースロケール、次に library のデフォルト (`en`) にフォールバックします。上書きするには `locales` を渡してください。`GT` インスタンスなしでフォーマットする場合は、スタンドアロンの [`formatCurrency`](/docs/platform/core/reference/utility-functions/formatting/format-currency) を参照してください。* ## 仕組み [#how-it-works] * **Currency スタイル。** 書式設定は、`style: 'currency'` と指定された `currency` コードを使って [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) に委ねられます。 * **ロケールの解決。** デフォルトでは、このメソッドはインスタンスの対象ロケールで書式設定を行い、次にソースロケール、最後にライブラリのデフォルト (`en`) へフォールバックします。`locales` 設定配列は参照されません。上書きするには、options で `locales` を渡してください。 * **記号の配置。** 通貨記号、桁区切り、小数の書式は、通貨の国ではなく、解決されたロケールに従います。 ## パラメータ [#parameters] | パラメータ | 説明 | 型 | 任意 | デフォルト | | ----------------------- | -------------------------------------------------------------------- | -------- | --- | ----- | | [`value`](#value) | 書式設定する数値です。 | `number` | いいえ | — | | [`currency`](#currency) | `USD` や `EUR` などの ISO 4217 通貨コードです。 | `string` | いいえ | — | | [`options`](#options) | `locales` のオーバーライドを追加した `Intl.NumberFormatOptions` を拡張する、書式設定用の構成です。 | `object` | はい | — | ### `value` [#value] **Type** `number` · **必須** 書式設定する数値の値です。 ### `currency` [#currency] **Type** `string` · **必須** `USD`、`EUR`、`JPY` などの ISO 4217 の通貨コード。 ### `options` [#options] **Type** `{ locales?: string | string[] } & Intl.NumberFormatOptions` · **省略可能** 書式設定用の構成です。追加の `locales` フィールドにより、`Intl.NumberFormatOptions` を拡張しています。 | 名前 | 説明 | Type | 省略可能 | デフォルト | | --------- | ------------------------- | -------------------- | ---- | ------------- | | `locales` | 書式設定に使用するロケールを上書きします。 | `string \| string[]` | はい | インスタンスの対象ロケール | | `style` | 数値の書式設定スタイル。デフォルトは通貨形式です。 | `string` | はい | `'currency'` | ## 戻り値 [#returns] **型** `string` ローカライズされた通貨文字列として書式設定された値です。 ## 例 [#examples] ```typescript import { GT } from 'generaltranslation'; const gt = new GT({ targetLocale: 'en-US' }); // デフォルトのインスタンスtargetLocale console.log(gt.formatCurrency(1234.56, 'USD')); // 出力: "$1,234.56" // 呼び出しごとにロケールを上書き console.log(gt.formatCurrency(1234.56, 'EUR', { locales: ['de-DE'] })); // 出力: "1.234,56 €" // 小数部の桁なし console.log(gt.formatCurrency(1234, 'JPY', { locales: ['ja-JP'] })); // 出力: "¥1,234" ``` ## メモ [#notes] * このメソッドは内部でブラウザネイティブの `Intl.NumberFormat` を使用しているため、金額はロケールの慣例に従います。 * 出力を細かく調整するには、`Intl.NumberFormatOptions` (たとえば `minimumFractionDigits`) を `locales` とあわせて渡してください。