Repository navigation
fix: promote compact token units at rounding boundaries - #365
Merged
chattymin merged 1 commit intoOct 5, 2026
Merged
Conversation
This was referenced Oct 10, 2026
donky-ey
pushed a commit
to donky-ey/PokeDexBar
that referenced
this pull request
Oct 15, 2026
…ttymin#365) 999,950 displayed as "1000.0K": the bucket was chosen from the raw value while one-decimal rounding pushed it past the unit boundary. Promote to the next unit at the rounded cutoff instead.
Strongorange
added a commit
to Strongorange/PokeTokenBar-windows
that referenced
this pull request
Oct 19, 2026
Port macOS chattymin#365 and chattymin#418: compact K/M switch to the next unit when rounding would display 1000.0 (999,950 shows as 1M, not 1000K), and percent/cost tiers are picked from the rounded string instead of the raw value (79.96 shows as 80%, 99.96 as \, 9,999.6 as \.0K).
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.
Summary
Promote compact token counts when one-decimal rounding would produce
1000Kor1000M. For example,999,950now displays1M, and999,999,999displays1B. Existing precision, trimmed zeros, and negative signs are preserved; cost formatting is unchanged.The unit was previously selected using the unrounded magnitude. Existing tests covered exact unit boundaries and ordinary values, but not values that round across a boundary. The new regression test covers immediately below/at the rounding thresholds, immediately below/at exact unit boundaries, and negative counterparts. A call-site sweep confirmed menu, usage, growth, and shop displays share this formatter; there is no duplicate token abbreviation implementation to update.
Rounding thresholds
K and M use one decimal place. The rollover therefore starts when the scaled value reaches
999.95, not when the raw token count reaches the next power of 1,000:999,949 / 1,000 = 999.949→999.9K.999,950 / 1,000 = 999.95→1000.0K→1M.999,950,000 / 1,000,000 = 999.95→1000.0M→1B.Using
999,999or999,999,999as the threshold would still leave earlier values displaying1000Kor1000M. The fix keeps rounding; it does not truncate counts.Comparison rendered from the actual Swift formatter outputs at the base and PR commits; this is a formatter-output table, not an app screenshot.
Type of change
Validation
swift buildpassed locally.llvm-cov show --show-regionsoutput for the formatter with the same harness.swift test --filter TokenFormatterTestsand./scripts/test-gate.shwere attempted, but this Mac has only Command Line Tools and cannot importXCTest. The standalone harness is not a substitute for the full test suite; CI should run the committed XCTest regression.build-testandsecret-scan: 1,381 tests executed, 14 skipped, 0 failures; logic-core line coverage 93.27%. The new boundary regression passed. Run: https://github.com/chattymin/PokeTokenBar/actions/runs/36311970875git diff --checkpassed.Checklist
swift buildandswift testpass locally