EdgeFunctionsListItem.utils.ts 516 B

1234567891011121314151617181920
  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. */
  11. export 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. const rounded = Number(value.toFixed(1))
  16. const clamped = Math.min(rounded, 100)
  17. if (clamped >= 100) return '100%'
  18. return `${clamped.toFixed(1)}%`
  19. }