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
|
// 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user