From 0715aef47766940712e1387d044c0dd52a11254b Mon Sep 17 00:00:00 2001 From: Rup Sarmah Date: Tue, 21 Jul 2026 17:52:40 +0530 Subject: [PATCH] fix(format): divide by 1e9 in formatLongNumber billions branch The billions branch of formatLongNumber divided by 1000000 while appending the 'b' suffix, so values >= 1e9 rendered about 1000x too large (1000000000 became '1000.0b' instead of '1.0b'). Divide by 1000000000 to match the 'b' unit, consistent with the sibling formatLongCurrency. Add regression tests for the billions branch. --- src/lib/format.test.ts | 2 ++ src/lib/format.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/format.test.ts b/src/lib/format.test.ts index b70b5f2e1..cf6d82c1b 100644 --- a/src/lib/format.test.ts +++ b/src/lib/format.test.ts @@ -27,6 +27,8 @@ test('formatNumber', () => { }); test('formatLongNumber', () => { + expect(format.formatLongNumber(1000000000)).toBe('1.0b'); + expect(format.formatLongNumber(2500000000)).toBe('2.5b'); expect(format.formatLongNumber(1200000)).toBe('1.2m'); expect(format.formatLongNumber(575000)).toBe('575k'); expect(format.formatLongNumber(10500)).toBe('10.5k'); diff --git a/src/lib/format.ts b/src/lib/format.ts index 07110d935..c791a2171 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -51,7 +51,7 @@ export function formatLongNumber(value: number) { const n = Number(value); if (n >= 1000000000) { - return `${(n / 1000000).toFixed(1)}b`; + return `${(n / 1000000000).toFixed(1)}b`; } if (n >= 1000000) { return `${(n / 1000000).toFixed(1)}m`;