17 lines
497 B
React
17 lines
497 B
React
export const PriceFormatter = (price, currency, currencyName) => {
|
|
const supportedCurrencies = ["USD", "EUR", "GBP"];
|
|
const symbolFormatter = supportedCurrencies.includes(currency)
|
|
? currency
|
|
: undefined;
|
|
|
|
const formatter = new Intl.NumberFormat("en", {
|
|
style: symbolFormatter,
|
|
currencyDisplay: "symbol",
|
|
minimumFractionDigits: 2,
|
|
});
|
|
|
|
const displayCurrencyName = symbolFormatter ? "" : currencyName;
|
|
|
|
return `${formatter.format(price)} ${displayCurrencyName}`;
|
|
};
|