Skip to content

fix(web): keep formatTokens monotonic across the k/M boundaries - #617

Merged
unohee merged 1 commit into
Intrect-io:mainfrom
aniruddhaadak80:fix/format-tokens-boundary
Sep 15, 2026
Merged

unohee merged 1 commit into
Intrect-io:mainfrom
aniruddhaadak80:fix/format-tokens-boundary

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

Summary

Fixes a rounding-boundary inconsistency in the dashboard token formatter: formatTokens(999.5) returned the bare string "1000" while formatTokens(1000) returned "1.0k", so a sub-thousand count displayed identically to a rounded-up thousand and broke monotonicity (999 -> "999", 999.5 -> "1000", 1000 -> "1.0k"). Same class of defect existed at the k/M edge (999999 -> "1000.0k" vs 1000000 -> "1.0M").

  • web/static/js/format.mjs:42-53 — round once with Math.round, branch on the rounded value, and promote >= 999950 to M so neither boundary can render "1000" / "1000.0k".
  • tests/web/format.test.ts:56-68 — regression tests pinning 999.5 -> "1.0k", 999.4/999 -> "999", 999999 -> "1.0M", 999949 -> "999.9k".

Reproduced before the fix with node --import=tsx importing web/static/js/format.mjs: formatTokens(999.5) === "1000", formatTokens(999.6) === "1000". After the fix: 1.0k, 999, 999, 1.0k, 1.0M, 999.9k, 1.2k, 2.5M for the probe sequence.

Related issue

No open issue exists (the repo currently has zero open issues). This is a proactive, no-behavior-change-except-the-bug fix discovered by scanning the dashboard formatting helpers (web/static/js/format.mjs) and its coverage (tests/web/format.test.ts).

Type of change

  • Bug fix
  • New feature
  • Refactor / chore
  • Docs

Checklist

  • npm run lint passes (no new warnings; format.mjs clean)
  • npm run typecheck passes (unaffected; dashboard JS is not in tsconfig.check.json)
  • npm run build passes (unaffected)
  • npm test passes for the touched area (tests/web/format.test.ts: 8 passed)
  • Docs updated if behavior changed (display-only bug fix; no docs change needed)
  • Commits follow Conventional Commits

@unohee
unohee merged commit 42145c1 into Intrect-io:main Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants