From 22eedf05f3c58823a1c3210e0a6f2c0036d8d5a7 Mon Sep 17 00:00:00 2001 From: natib21 Date: Tue, 30 Jun 2026 15:24:36 +0000 Subject: [PATCH] fix --- .../backoffice/src/pages/fleet/format.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 apps/edr-freight-web/backoffice/src/pages/fleet/format.ts diff --git a/apps/edr-freight-web/backoffice/src/pages/fleet/format.ts b/apps/edr-freight-web/backoffice/src/pages/fleet/format.ts new file mode 100644 index 000000000..6193ca58c --- /dev/null +++ b/apps/edr-freight-web/backoffice/src/pages/fleet/format.ts @@ -0,0 +1,16 @@ +/** Shared formatting helpers for the fleet-management pages. */ + +/** Format a number as Ethiopian Birr, e.g. 12345.6 → "ETB 12,346". */ +export function formatETB(amount: number, fractionDigits = 0): string { + const value = Number.isFinite(amount) ? amount : 0; + return `ETB ${value.toLocaleString("en-US", { + minimumFractionDigits: fractionDigits, + maximumFractionDigits: fractionDigits, + })}`; +} + +/** Safe percentage of `part` over `total`, rounded, 0 when total is 0. */ +export function pct(part: number, total: number): number { + if (!total || !Number.isFinite(total) || !Number.isFinite(part)) return 0; + return Math.round((part / total) * 100); +}