fix(frontend): promote token count display at unit boundaries - #689
Merged
junhoyeo merged 2 commits intoJun 8, 2026
Merged
Conversation
formatTokenCount used toFixed(1) after dividing by the unit, which rounds 999.95+ to '1000.0'. A count of 999,950 displayed as '1000.0K' instead of '1.0M'; 999,999,500 as '1000.0M' instead of '1.0B'. Check if the divided value >= 999.95 before formatting and promote to the next unit when it does. Closes junhoyeo#474
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
Frontend CI failing due to PR #685 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
formatTokenCountinpackages/frontend/src/lib/utils.tsdisplays token counts in compact form (K/M/B/T) usingtoFixed(1)after dividing by the unit. When a value is near a unit boundary,toFixed(1)rounds up to"1000.0", producing displays like:999,950→"1000.0K"(should be"1.0M")999,999,500→"1000.0M"(should be"1.0B")This is the root cause of #474 — tokens on the profile page appearing "rounded up" with the wrong unit.
Fix
Before formatting, check if the divided value is ≥ 999.95 (the threshold where
toFixed(1)rounds to"1000.0"). When it is, promote to the next unit:Same pattern for K→M and B→T boundaries.
Verification
New test file
__tests__/lib/formatTokenCount.test.tscovers:Closes #474
Summary by cubic
Fixes token count rounding near unit boundaries in
formatTokenCountso we don’t display "1000.0K/M/B". Values that would round up are promoted to the next unit (e.g., 999,950 → 1.0M); fixes #474.packages/frontend/__tests__/lib/formatTokenCount.test.tscovering normal and boundary cases.Written for commit d3d655b. Summary will update on new commits.