Variable.formatNumber - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatNumber
Variable: formatNumber
constformatNumber: (value, ...args) =>string
Defined in: lib/number-format/index.ts:61
Formats a number with support for various styles, units, and notations.
Parameters
| Parameter | Type |
|---|---|
value |
number |
...args |
[string | string[], NumberFormatOptions] |
Returns
string
Example
import { formatNumber } from '@sumup-oss/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.