mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
24 lines
622 B
TypeScript
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,
|
|
})}`;
|
|
}
|