formatNumber renders NaN for values >= 1e15 (off-by-one unit index)
Author: yashs33244Created Jun 15, 2026Updated Jun 15, 2026
Bug
frontend/src/util/numbers.tsx formatNumber clamps the unit index with sizes.length instead of sizes.length - 1. For n >= 1e15, Math.floor(Math.log(n) / Math.log(1000)) is 5 or more, so i becomes 5, sizes[5] (['', 'K', 'M', 'B', 'T']) is undefined, and the result is NaN instead of a formatted string. This is reachable from the Graphing y-axis / bar-label formatters, which format arbitrary metric values.
Repro
formatNumber(1e15) → NaN (expected 1000T).
Fix
Clamp the index to sizes.length - 1. Output for all n < 1e15 is unchanged.
Source: highlight/highlight