Update formatCurrency to handle optional currencyCode and default to EUR

This commit is contained in:
Knee Cola
2025-11-22 23:06:04 +01:00
parent c025c6f2ce
commit a2cea49e9f

View File

@@ -1,4 +1,4 @@
export const formatCurrency = (amount: number, currencyCode: string = "EUR") => { export const formatCurrency = (amount: number, currencyCode?: string | null) => {
// format number with 2 decimal places and a thousand separator // format number with 2 decimal places and a thousand separator
// amount is in cents // amount is in cents
const amountInUnits = amount / 100; const amountInUnits = amount / 100;
@@ -7,7 +7,7 @@ export const formatCurrency = (amount: number, currencyCode: string = "EUR") =>
try { try {
return new Intl.NumberFormat('hr-HR', { return new Intl.NumberFormat('hr-HR', {
style: 'currency', style: 'currency',
currency: currencyCode, currency: currencyCode ?? "EUR",
minimumFractionDigits: 2, minimumFractionDigits: 2,
maximumFractionDigits: 2, maximumFractionDigits: 2,
}).format(amountInUnits); }).format(amountInUnits);