fix(web): stop formatUsageNumber rendering 1000.0K at unit boundaries#1340
Open
abhay-codes07 wants to merge 1 commit into
Open
fix(web): stop formatUsageNumber rendering 1000.0K at unit boundaries#1340abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
One-decimal rounding pushed values just below a unit over the top: 999,950
through 999,999 divided by 1,000 give 999.95..999.999, which toFixed(1) rounds
to "1000.0", so the usage counter displayed "1000.0K" instead of "1.0M". The
same happened at the million boundary ("1000.0M"). Promote to the next unit
when the scaled value rounds to 1000, and add a billions tier so large counts
render as "1.0B" rather than "1000.0M". Adds unit tests around both boundaries.
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
formatUsageNumberscales the value and formats it with one decimal:toFixed(1)rounds, so any value from 999,950 to 999,999 becomes999.95..999.999→"1000.0", and the usage counter shows "1000.0K" instead of "1.0M". The same artifact appears at the million boundary (999,999,950 → "1000.0M").Fix
When the scaled value rounds up to 1000, promote it to the next unit, and add a billions tier so very large counts read "1.0B" instead of "1000.0M":
Tests
Added
billing-utils.test.ts(bun:test) covering both boundaries: 999,950 and 999,999 → "1.0M", 999,949 → "999.9K" (still rounds within band), 999,999,950 → "1.0B", plus the existing 50K / 1.5M / 2M cases. 5 tests pass.