Skip to content

Function.resolveNumberFormat

kodiakhq[bot] edited this page Dec 2, 2024 · 53 revisions

@sumup-oss/intl / resolveNumberFormat

Function: resolveNumberFormat()

resolveNumberFormat(locales?, options?): null | NumberFormat

Resolves the locale and collation options that are used to format a number.

Parameters

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

Returns

null | NumberFormat

Example

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

resolveNumberFormat();
// {
//   'locale': 'en-US',
//   'numberingSystem': 'latn',
//   'style': 'decimal',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 0,
//   'maximumFractionDigits': 3,
//   'useGrouping': true,
//   'groupDelimiter': ',',
//   'decimalDelimiter': '.',
// }

resolveNumberFormat(['ban', 'id']);
// {
//   'locale': 'id',
//   'numberingSystem': 'latn',
//   'style': 'decimal',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 0,
//   'maximumFractionDigits': 3,
//   'useGrouping': true,
//   'groupDelimiter': '.',
//   'decimalDelimiter': ',',
// }

resolveNumberFormat('en-GB', {
  style: 'unit',
  unit: 'liter',
  unitDisplay: 'long',
});
// {
//   'locale': 'en-GB',
//   'numberingSystem': 'latn',
//   'style': 'unit',
//   'unit': 'liter',
//   'unitDisplay': 'long',
//   'minimumIntegerDigits': 1,
//   'minimumFractionDigits': 0,
//   'maximumFractionDigits': 3,
//   'useGrouping': true,
//   'notation': 'standard',
//   'signDisplay': 'auto',
//   'groupDelimiter': ',',
//   'decimalDelimiter': '.',
// }

Remarks

For convenience, groupDelimiter anddecimalDelimiter are returned in addition to the Intl.ResolvedNumberFormatOptions.

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

Defined in

lib/number-format/index.ts:293