Skip to content

Function.resolveCurrencyFormat

connor-baer edited this page Dec 5, 2024 · 56 revisions

@sumup-oss/intl / resolveCurrencyFormat

Function: resolveCurrencyFormat()

resolveCurrencyFormat(locales?, currency?, options?): null | NumberFormat

Resolves the locale and collation options that are used to format a number in the country's official currency.

Parameters

Parameter Type
locales? string | string[]
currency? string
options? NumberFormatOptions

Returns

null | NumberFormat

Example

import { resolveCurrencyFormat } from '@sumup-oss/intl';

resolveCurrencyFormat();
// {
//   'locale': 'en-US',
//   'numberingSystem': 'latn',
//   'style': 'currency',
//   'currency': 'USD',
//   'currencyDisplay': 'symbol',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 2,
//   'maximumFractionDigits': 2,
//   'useGrouping': true,
//   'groupDelimiter': '.',
//   'decimalDelimiter': ',',
//   'currencySymbol': '$',
//   'currencyPosition': 'prefix',
// }

resolveCurrencyFormat('ja-JP');
// {
//   'locale': 'ja-JP',
//   'numberingSystem': 'latn',
//   'style': 'currency',
//   'currency': 'JPY',
//   'currencyDisplay': 'symbol',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 0,
//   'maximumFractionDigits': 0,
//   'useGrouping': true,
//   'groupDelimiter': ',',
//   'decimalDelimiter': undefined,
//   'currencySymbol': '¥',
//   'currencyPosition': 'prefix',
// }

resolveCurrencyFormat('en-GB', { currencyDisplay: 'name' });
// {
//   'locale': 'en-GB',
//   'numberingSystem': 'latn',
//   'style': 'currency',
//   'currency': 'GBP',
//   'currencyDisplay': 'symbol',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 2,
//   'maximumFractionDigits': 2,
//   'useGrouping': true,
//   'groupDelimiter': ',',
//   'decimalDelimiter': '.',
//   'currencySymbol': 'British pounds',
//   'currencyPosition': 'suffix',
// }

Remarks

For convenience, groupDelimiter,decimalDelimiter, currencySymbol, and currencyPosition are returned in addition to the Intl.ResolvedNumberFormatOptions.

In runtimes that don't support the Intl.NumberFormat.resolvedOptions API, null is returned.

The COP and HUF currencies are formatted without decimals.

Defined in

lib/number-format/index.ts:370