mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 06:00:55 +00:00
17 lines
666 B
TypeScript
17 lines
666 B
TypeScript
/** 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);
|
|
}
|