Skip to content

Function.formatNumber

connor-baer edited this page Aug 14, 2024 · 45 revisions

@sumup/intl / formatNumber

Function: formatNumber()

formatNumber(value, locales?, options?): string

Formats a number with support for various styles, units, and notations.

Parameters

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

Returns

string

Example

import { formatNumber } from '@sumup/intl';

formatNumber(12345.67, 'de-DE'); // '12.345,67'
formatNumber(-0.89, ['ban', 'id']); // '-0,89'
formatNumber(16, 'en-GB', {
  style: 'unit',
  unit: 'liter',
  unitDisplay: 'long',
}); // 16 litres

Remarks

In runtimes that don't support the Intl.NumberFormat API, the number is formatted using the Number.toLocaleString API.

Defined in

lib/number-format/index.ts:67