Update formatCurrency to handle optional currencyCode and default to EUR
This commit is contained in:
@@ -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
|
||||
// amount is in cents
|
||||
const amountInUnits = amount / 100;
|
||||
@@ -7,7 +7,7 @@ export const formatCurrency = (amount: number, currencyCode: string = "EUR") =>
|
||||
try {
|
||||
return new Intl.NumberFormat('hr-HR', {
|
||||
style: 'currency',
|
||||
currency: currencyCode,
|
||||
currency: currencyCode ?? "EUR",
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(amountInUnits);
|
||||
|
||||
Reference in New Issue
Block a user