mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 15:32:27 -05:00
29be4f66d4
Add-on purchase preview page GitOrigin-RevId: 660e39a94e6112af020ea783d6acf01a19432605
28 lines
662 B
TypeScript
28 lines
662 B
TypeScript
import getMeta from '@/utils/meta'
|
|
|
|
const DEFAULT_LOCALE = getMeta('ol-i18n')?.currentLangCode ?? 'en'
|
|
|
|
export function formatCurrencyLocalized(
|
|
amount: number,
|
|
currency: string,
|
|
locale: string = DEFAULT_LOCALE,
|
|
stripIfInteger = false
|
|
): string {
|
|
const options: Intl.NumberFormatOptions = { 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}`
|
|
}
|