Variable.formatCurrencyToParts - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatCurrencyToParts
Variable: formatCurrencyToParts
constformatCurrencyToParts: (value, ...args) =>NumberFormatPart[]
Defined in: lib/number-format/index.ts:214
Formats a number as currency to parts with support for various notations.
Parameters
| Parameter | Type |
|---|---|
value |
number |
...args |
[string | string[], string, NumberFormatOptions] |
Returns
NumberFormatPart[]
Example
import { formatCurrencyToParts } from '@sumup-oss/intl';
formatCurrencyToParts(12345.67, 'de-DE', 'EUR');
// [
// { type: "integer", value: "12" },
// { type: "group", value: "." },
// { type: "integer", value: "345" },
// { type: "decimal", value: "," },
// { type: "fraction", value: "67" },
// { type: "literal", value: " " },
// { type: "currency", value: "€" },
// ]
formatCurrencyToParts(-89, 'ja-JP', 'JPY');
// [
// { type: "minusSign", value: "-" },
// { type: "currency", value: "¥" },
// { type: "integer", value: "89" },
// ]
formatCurrencyToParts(16, 'en-GB', 'GBP', { currencyDisplay: 'name' });
// [
// { type: "integer", value: "16" },
// { type: "decimal", value: "." },
// { type: "fraction", value: "00" },
// { type: "literal", value: " " },
// { type: "currency", value: "British pounds" },
// ]
Remarks
When currency is omitted, it is inferred from the locale's region. This behavior
is deprecated — always pass an explicit currency code.
In runtimes that don't support the Intl.NumberFormat.formatToParts API,
the currency is localized and returned as a single integer part.
The COP and HUF currencies are formatted without decimals.