Skip to content

fix formatPrefix rounding after scaling - #167

Open
draarivpatel-ui wants to merge 1 commit into
d3:mainfrom
draarivpatel-ui:l954/format-prefix-scaling
Open

draarivpatel-ui wants to merge 1 commit into
d3:mainfrom
draarivpatel-ui:l954/format-prefix-scaling

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #132.

Problem

formatPrefix multiplies each input by a binary floating-point reciprocal before fixed formatting. That extra multiplication can move an exact decimal rounding boundary to either side of the boundary:

formatPrefix(",.2", 1e3)(1555)
// was "1.55k", now "1.56k"

Fix

Format at the equivalent significant-digit position before applying the decimal exponent shift. Since the SI scale is always a power of ten, rounding the unscaled value at that digit position is the same rounding operation, without the additional multiplication error. The result is then rendered as fixed decimal notation.

The existing NaN behavior for a zero or infinite prefix reference is preserved.

Verification

  • Added regression coverage for the reported case, adjacent values, and half-way cases near zero.
  • npx vitest run: 24 files, 169 tests passed.
  • npm run lint: passed.
  • npm run prepublishOnly: passed.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

formatPrefix will sometimes not perform rounding

2 participants