Skip to content

Add lossless option to fmtQuantity#4454

Merged
amcclain merged 6 commits into
developfrom
lossless-quantity-format
Jun 24, 2026
Merged

Add lossless option to fmtQuantity#4454
amcclain merged 6 commits into
developfrom
lossless-quantity-format

Conversation

@lbwexler

@lbwexler lbwexler commented Jun 24, 2026

Copy link
Copy Markdown
Member

Adds a lossless option to fmtQuantity (issue #4219). When set, the formatter compacts to millions / billions units only when doing so loses no precision; otherwise it renders the full value at its natural precision.

  • 7,100,0007.10m (exact, compacts)
  • 7,100,1007,100,100 (would lose the trailing 100, so renders full)
  • 123.456 with lossless123.456 (no longer rounded to 123)

Changes

  • New lossless opt on QuantityFormatOptions (default false).
  • Extracted the auto/fixed precision resolution out of buildFormatConfig into a shared parsePrecision helper, reused by the compaction-exactness check.
  • Compaction decision uses the standard display precision as its threshold; lossless independently drives full-precision rendering when not compacting.

Closes #4219

Not changing the default tooltip

The issue also floated defaulting tooltip: true for non-lossless lossy renders. Skipped: that would silently add hover tooltips to every existing fmtQuantity call site - a broad, app-wide behavior change disproportionate to an opt-in feature. lossless already surfaces the lost precision inline, and tooltip: true remains available per-call.

lbwexler added 4 commits June 24, 2026 08:11
Compacts to millions / billions units only when doing so loses no precision, rendering the full value (at natural precision) otherwise - e.g. `7,100,100` stays `7,100,100` rather than collapsing to `7.10m`.

- Extracts the auto/fixed precision resolution from `buildFormatConfig` into a shared `parsePrecision` helper, reused by the compaction-exactness check.
- The compaction decision uses the standard display precision as its threshold; `lossless` independently drives rendering at full precision when not compacting.

Closes #4219
@lbwexler lbwexler marked this pull request as ready for review June 24, 2026 18:57
@lbwexler lbwexler requested a review from amcclain June 24, 2026 18:58
amcclain added 2 commits June 24, 2026 16:13
- Escape `>=` in `QuantityFormatOptions` doc comments so TSDoc doesn't read the bare `>` as an HTML tag start.
- Drop a redundant inline triple-backtick from a prose JSDoc comment in `ts-registry.ts` that the parser mistook for a code-fence opener (pre-existing, from #4406).

Claude-Session: https://claude.ai/code/session_01Ce4kWUGq9joZDQwGSAbvEu
@amcclain amcclain merged commit 758f383 into develop Jun 24, 2026
3 checks passed
@amcclain amcclain deleted the lossless-quantity-format branch June 24, 2026 23:33
@amcclain

Copy link
Copy Markdown
Member

Thanks for landing this - Toolbox formatter demo updated @ xh/toolbox@625e727

@lbwexler

lbwexler commented Jun 25, 2026 via email

Copy link
Copy Markdown
Member Author

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.

The fmtQuantity util should have a lossless option

2 participants