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:184
Formats a number in the country's official currency 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');
// [
// { 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', null, { currencyDisplay: 'name' });
// [
// { type: "integer", value: "16" },
// { type: "decimal", value: "." },
// { type: "fraction", value: "00" },
// { type: "literal", value: " " },
// { type: "currency", value: "British pounds" },
// ]
Remarks
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.