Files
edr-platform/apps/edr-freight-web/portal/src/lib/currency.ts
2026-06-29 13:54:14 +00:00

24 lines
622 B
TypeScript

/** Currency code carried on invoices / dashboard figures (ETB, USD, DJF, …). */
export type Currency = string;
const SYMBOLS: Record<string, string> = {
USD: "$",
ETB: "Br",
DJF: "DJF",
};
/**
* Format a money amount with its currency symbol, e.g. `Br 12,500.00`.
* Unknown currency codes fall back to printing the raw code.
*/
export function formatCurrency(
amount: number,
currency: Currency = "ETB",
): string {
const symbol = SYMBOLS[currency] ?? currency;
return `${symbol} ${Number(amount ?? 0).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}