-
Notifications
You must be signed in to change notification settings - Fork 4
Function.formatCurrencyToParts
connor-baer edited this page Oct 17, 2024
·
56 revisions
@sumup-oss/intl / formatCurrencyToParts
formatCurrencyToParts(
value
,locales
?,currency
?,options
?):NumberFormatPart
[]
Formats a number in the country's official currency with support for various notations.
Parameter | Type |
---|---|
value |
number |
locales ? |
string | string [] |
currency ? |
string |
options ? |
NumberFormatOptions |
NumberFormatPart
[]
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" },
// ]
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.