Skip to content

fix: parseUnits rounding for long fractional values#4857

Open
nikhilkumar1612 wants to merge 1 commit into
wevm:mainfrom
nikhilkumar1612:main
Open

fix: parseUnits rounding for long fractional values#4857
nikhilkumar1612 wants to merge 1 commit into
wevm:mainfrom
nikhilkumar1612:main

Conversation

@nikhilkumar1612

Copy link
Copy Markdown
Contributor

Fixes #4855

This PR fixes parseUnits rounding for long fractional values near half boundaries.

Previously, parseUnits used Number(...) and Math.round(...) when the fractional part exceeded the requested decimal precision. For long decimal strings, JavaScript floating-point conversion can round values like .49999999999999999999 to 0.5, causing parseUnits to round up incorrectly.

This changes rounding to stay in decimal string/BigInt space by checking the first discarded fractional digit and carrying manually.

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2f256d0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

@nikhilkumar1612 is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug]: parseUnits mis-rounds long fractional tails via Math.round(Number(...))

1 participant