diff --git a/apps/web/src/features/monitoring/MonitoringCenterPage.test.tsx b/apps/web/src/features/monitoring/MonitoringCenterPage.test.tsx index de7ca7fe5..58e1c6148 100644 --- a/apps/web/src/features/monitoring/MonitoringCenterPage.test.tsx +++ b/apps/web/src/features/monitoring/MonitoringCenterPage.test.tsx @@ -148,7 +148,7 @@ describe('MonitoringCenterPage summary cards', () => { expect(html).toContain('_summaryGrid'); expect(html.match(/ { if (!Number.isFinite(value)) return '0'; if (Math.abs(value) >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(2)}B`; if (Math.abs(value) >= 1_000_000) return `${(value / 1_000_000).toFixed(2)}M`; - if (Math.abs(value) >= 1_000) return `${(value / 1_000).toFixed(1)}K`; + if (Math.abs(value) >= 10_000) return `${(value / 1_000).toFixed(1)}K`; return String(Math.round(value)); }; diff --git a/apps/web/src/features/usage-analytics/usageAnalyticsPresentation.ts b/apps/web/src/features/usage-analytics/usageAnalyticsPresentation.ts index 395fd0194..914c89e68 100644 --- a/apps/web/src/features/usage-analytics/usageAnalyticsPresentation.ts +++ b/apps/web/src/features/usage-analytics/usageAnalyticsPresentation.ts @@ -94,7 +94,7 @@ const formatCompactNumber = (value: number) => { if (!Number.isFinite(value)) return '0'; if (Math.abs(value) >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(2)}B`; if (Math.abs(value) >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`; - if (Math.abs(value) >= 1_000) return `${(value / 1_000).toFixed(1)}K`; + if (Math.abs(value) >= 10_000) return `${(value / 1_000).toFixed(1)}K`; return String(Math.round(value)); }; diff --git a/apps/web/src/utils/usage.test.ts b/apps/web/src/utils/usage.test.ts index 286c5e296..c71b42b07 100644 --- a/apps/web/src/utils/usage.test.ts +++ b/apps/web/src/utils/usage.test.ts @@ -16,7 +16,9 @@ import { maskSensitiveText } from './format'; describe('formatCompactNumber', () => { it('keeps large values compact as data grows beyond millions', () => { expect(formatCompactNumber(999)).toBe('999'); - expect(formatCompactNumber(1_200)).toBe('1.2K'); + expect(formatCompactNumber(1_200)).toBe('1200'); + expect(formatCompactNumber(9_999)).toBe('9999'); + expect(formatCompactNumber(12_000)).toBe('12.0K'); expect(formatCompactNumber(999_950)).toBe('1.0M'); expect(formatCompactNumber(2_795_200_000)).toBe('2.8B'); expect(formatCompactNumber(1_200_000_000_000)).toBe('1.2T'); diff --git a/apps/web/src/utils/usage.ts b/apps/web/src/utils/usage.ts index e4e656e1b..7b10f24fa 100644 --- a/apps/web/src/utils/usage.ts +++ b/apps/web/src/utils/usage.ts @@ -844,19 +844,19 @@ export function formatCompactNumber(value: number): string { const abs = Math.abs(num); if (abs === 0) return '0'; const units = [ - { threshold: 1_000_000_000_000_000, suffix: 'P' }, - { threshold: 1_000_000_000_000, suffix: 'T' }, - { threshold: 1_000_000_000, suffix: 'B' }, - { threshold: 1_000_000, suffix: 'M' }, - { threshold: 1_000, suffix: 'K' }, + { threshold: 1_000_000_000_000_000, divisor: 1_000_000_000_000_000, suffix: 'P' }, + { threshold: 1_000_000_000_000, divisor: 1_000_000_000_000, suffix: 'T' }, + { threshold: 1_000_000_000, divisor: 1_000_000_000, suffix: 'B' }, + { threshold: 1_000_000, divisor: 1_000_000, suffix: 'M' }, + { threshold: 10_000, divisor: 1_000, suffix: 'K' }, ]; const unit = units.find((item) => abs >= item.threshold); if (unit) { - const formatted = (num / unit.threshold).toFixed(1); + const formatted = (num / unit.divisor).toFixed(1); const nextUnit = units[units.indexOf(unit) - 1]; if (nextUnit && Math.abs(Number(formatted)) >= 1000) { - return `${(num / nextUnit.threshold).toFixed(1)}${nextUnit.suffix}`; + return `${(num / nextUnit.divisor).toFixed(1)}${nextUnit.suffix}`; } return `${formatted}${unit.suffix}`; }