diff --git a/services/web/app/src/util/currency.js b/services/web/app/src/util/currency.js index 4a9972d423..52b6411a17 100644 --- a/services/web/app/src/util/currency.js +++ b/services/web/app/src/util/currency.js @@ -14,19 +14,23 @@ * @returns {string} */ function formatCurrencyLocalized(amount, currency, locale, stripIfInteger) { + const options = { style: 'currency', currency } if (stripIfInteger && Number.isInteger(amount)) { + options.minimumFractionDigits = 0 + } + + try { return amount.toLocaleString(locale, { - style: 'currency', - currency, - minimumFractionDigits: 0, + ...options, currencyDisplay: 'narrowSymbol', }) - } - return amount.toLocaleString(locale, { - style: 'currency', - currency, - currencyDisplay: 'narrowSymbol', - }) + } catch {} + + try { + return amount.toLocaleString(locale, options) + } catch {} + + return `${currency} ${amount}` } module.exports = { diff --git a/services/web/frontend/js/shared/utils/currency.ts b/services/web/frontend/js/shared/utils/currency.ts index abf52bcdbf..6b0dbb72a8 100644 --- a/services/web/frontend/js/shared/utils/currency.ts +++ b/services/web/frontend/js/shared/utils/currency.ts @@ -23,17 +23,21 @@ export function formatCurrencyLocalized( locale: string, stripIfInteger = false ): string { + const options: Intl.NumberFormatOptions = { style: 'currency', currency } if (stripIfInteger && Number.isInteger(amount)) { + options.minimumFractionDigits = 0 + } + + try { return amount.toLocaleString(locale, { - style: 'currency', - currency, - minimumFractionDigits: 0, + ...options, currencyDisplay: 'narrowSymbol', }) - } - return amount.toLocaleString(locale, { - style: 'currency', - currency, - currencyDisplay: 'narrowSymbol', - }) + } catch {} + + try { + return amount.toLocaleString(locale, options) + } catch {} + + return `${currency} ${amount}` }