Skip to content

Pick formatter precision from the rounded value, not the raw one - #418

Merged
chattymin merged 1 commit into
chattymin:mainfrom
Borisserz:fix/formatter-rounding-boundaries
Oct 5, 2026
Merged

chattymin merged 1 commit into
chattymin:mainfrom
Borisserz:fix/formatter-rounding-boundaries

Conversation

@Borisserz

Copy link
Copy Markdown
Contributor

Summary

Fixes #417. TokenFormatter.percent and costCompact chose their precision from the raw value and rounded afterwards. When rounding crossed a boundary, the output contradicted the choice: 79.96 became 80.0%, 99.96 became $100.0, and 9_999.6 became $10000 instead of $10.0K.

Both functions now format with the bucket's precision first and pick the bucket from the formatted value. Output for every non-boundary value is unchanged: the existing testFormatterEdges assertions still pass as-is.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Other:

UI changes

Before After
Menu bar 5h 80.0% next to 7d 88%; recap ▲13.0%; cost $100.0 / $10000 5h 80%, ▲13%, $100 / $10.0K

Validation

  • New LocalUsageCacheTests.testFormatterRoundingBoundaries with pairs just above and just below each boundary (79.96/79.94, 99.96/99.94, 9_999.6/9_999.4, plus 99.97 and 0.04). On unfixed main it fails with 5 failures. With the fix, all pass.
  • Full swift test: 1385 tests, 0 failures (17 skipped, as on main).
  • Class sweep: L.difficultyValue has the same shape, but snapDifficulty snaps every slider value to 2 significant digits, so no input can round across its boundaries. Left unchanged and noted in the defect log.
  • Added a defect-log entry under display/UI.

Checklist

  • swift build and swift test pass locally
  • PR title and description are written in English
  • UI changes are described above (before/after — images optional)
  • No copyrighted assets, secrets, or private tooling references are committed (see CONTRIBUTING)
  • Tests were added or updated for this change

@chattymin
chattymin merged commit 711fca7 into chattymin:main Oct 5, 2026
2 checks passed
donky-ey pushed a commit to donky-ey/PokeDexBar that referenced this pull request Oct 15, 2026
… (upstream chattymin#418)

79.96 printed as "80.0%" and 99.96 as "$100.0": the branch compared the
raw value while the format rounded it past the cutoff. Branch on the
rounded string 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).
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.

Formatter prints "80.0%" and "$10000" when rounding crosses a precision boundary

2 participants