Skip to content

fix(shared): token counts drop trailing zeros, so 1,500 reads 1.5K - #44158

Closed
AymanKhan9 wants to merge 3 commits into
pingdotgg:mainfrom
AymanKhan9:fix/usage-token-trailing-zero
Closed

AymanKhan9 wants to merge 3 commits into
pingdotgg:mainfrom
AymanKhan9:fix/usage-token-trailing-zero

Conversation

@AymanKhan9

Copy link
Copy Markdown
Contributor

Token counts on the Usage page, in the model usage dialog and in the mobile composer's compaction notice showed a trailing zero, for example 1.50K for 1,500 tokens and 2.30M for 2.3M. formatTokens rounds to two decimals under 10 and one under 100, but the cleanup regex only removed decimals that were all zeros (.00), so a single trailing zero stayed.

trim now goes through Number, which drops any trailing zeros: String(Number(value.toFixed(digits))). Whole and three-digit values (12K, 100K) are unchanged. Added a test that fails on main (Expected "1.5K", received "1.50K") and passes with the fix.

Surfaces: formatTokens lives in packages/shared and is used by web/desktop (Usage page, model usage dialog) and mobile (Usage screen, composer), so all of them pick up the fix. Provider-agnostic.

Model: Claude Opus 5.5, via Claude Code in T3 Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The token formatter now removes trailing fractional zeros from formatted values. Tests verify formatting for values in thousands and millions.

Changes: Token suffix formatting

Layer / File(s) Summary
Normalize formatted decimals
packages/shared/src/usageFormat.ts, packages/shared/src/usageFormat.test.ts
trim converts the fixed-decimal result through a number before returning a string. Tests verify that 1,500 formats as 1.5K and -1,200,000 as -1.2M.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#35634: It changes the same formatTokens rounding and trimming path to advance suffixes when a rounded value reaches 1000.

Suggested reviewers: saphid, only21mil

Merge Risk: Minimal · up to a1a45

Compact token counts will show 1.5K instead of 1.50K across the Usage surfaces. The change is small and low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the actual change: token counts no longer keep a trailing zero, with the 1,500 to 1.5K example. It matches the raw summary, which says trim now goes through Number and drops trailing z…
Description check Passed The description follows the template's main sections in substance. It has a clear problem statement with a concrete example, and it explains the change through the Number-based trim. Verification give…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the actual change: token counts no longer keep a trailing zero, with the 1,500 to 1.5K example. It matches the raw summary, which says trim now goes through Number and drops trailing zeros. The fix(shared) prefix follows conventional commit style and names the affected package.

Full details: Description check

Explanation

The description follows the template's main sections in substance. It has a clear problem statement with a concrete example, and it explains the change through the Number-based trim. Verification gives a specific failing-then-passing test with the observed message. The Scope section is not filled in: it does not link an issue or explain why no issue is needed, and it does not say whether a maintainer requested the PR. The template's model attribution line is present. Overall the description is mostly complete, with one required section partly missing.

Resolution

Optional: in the Scope section, link the issue that shows the bug, or state why a small obvious fix needs no issue. Also state whether a maintainer requested the PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 768b1f9 and a1a45bb.

Files selected for processing: 1

  • packages/shared/src/usageFormat.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 27, 2026
@juliusmarminge juliusmarminge added takeover:needs-julius Takeover done; route gate says Julius decides and removed takeover:in-progress A takeover lead is working on this PR labels Nov 27, 2026
@AymanKhan9 AymanKhan9 closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). takeover:needs-julius Takeover done; route gate says Julius decides vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants