EdgeFunctionsListItem.utils.ts20 lines · main
1/**
2 * Formats a numeric error rate (0–100) into a display string.
3 *
4 * Examples:
5 * 0 → "0%"
6 * 0.05 → "<0.1%"
7 * 0.1 → "0.1%"
8 * 1.567 → "1.6%"
9 * 100 → "100%"
10 */
11export function formatErrorRate(value: number): string {
12 if (value === 0) return '0%'
13 if (value >= 100) return '100%'
14 if (value < 0.1) return '<0.1%'
15
16 const rounded = Number(value.toFixed(1))
17 const clamped = Math.min(rounded, 100)
18 if (clamped >= 100) return '100%'
19 return `${clamped.toFixed(1)}%`
20}