profileShare

rasmusjy / splitapp-frontend-vue

Read-only snapshot

No repository description.

main default branch 96 files Expires Sep 13, 2026, 9:06 AM
formatCurrency.ts 472 bytes
1 import i18n from '@/i18n'
2
3 export function formatCurrency(
4 amount: number,
5 symbol?: string | null,
6 decimals: number = 2,
7 ): string {
8 const locale = i18n.global.locale.value === 'et' ? 'et-EE' : 'en-US'
9 const abs = Math.abs(amount)
10 const formatted = abs.toLocaleString(locale, {
11 minimumFractionDigits: decimals,
12 maximumFractionDigits: decimals,
13 })
14 const sign = amount < 0 ? '-' : ''
15 const sym = symbol ?? ''
16 return `${sign}${sym}${formatted}`
17 }
18