Files
overleaf-cep/services/web/app/src/util/currency.js
T
Eric Mc Sween 250acbf33c Merge pull request #20520 from overleaf/em-ts-import
Use new import JSDoc syntax for Typescript annotations

GitOrigin-RevId: 782456d637fc8f2de6163b5d70fabf06c1d74964
2024-09-23 08:04:47 +00:00

39 lines
816 B
JavaScript

/**
* This file is duplicated from services/web/frontend/js/shared/utils/currency.ts
*/
/**
* @import { CurrencyCode } from '@/shared/utils/currency'
*/
/**
* @param {number} amount
* @param {CurrencyCode} currency
* @param {string} locale
* @param {boolean} stripIfInteger
* @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, {
...options,
currencyDisplay: 'narrowSymbol',
})
} catch {}
try {
return amount.toLocaleString(locale, options)
} catch {}
return `${currency} ${amount}`
}
module.exports = {
formatCurrencyLocalized,
}