Skip to content

fix(unit): delegate parse/format unit utils to Ox's Value module#4859

Merged
jxom merged 2 commits into
mainfrom
claude/viem-4855-ox-value-2r9jku
Jul 18, 2026
Merged

fix(unit): delegate parse/format unit utils to Ox's Value module#4859
jxom merged 2 commits into
mainfrom
claude/viem-4855-ox-value-2r9jku

Conversation

@jxom

@jxom jxom commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #4855. parseUnits rounded long fractional tails with
Math.round(Number(...)), which is not exact for IEEE-754 doubles and
could round the wrong way (e.g. parseUnits('1.4499999999999999999', 1)
returned 15n instead of 14n).

Reuses Ox's Value module (from/format/fromEther/fromGwei/
formatEther/formatGwei), which rounds exactly in decimal space, and
adds regression tests for the reported cases.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01Y5AhB5FfyPaJLykDnV8Eqi

Fixes #4855. `parseUnits` rounded long fractional tails with
`Math.round(Number(...))`, which is not exact for IEEE-754 doubles and
could round the wrong way (e.g. parseUnits('1.4499999999999999999', 1)
returned 15n instead of 14n).

Reuses Ox's `Value` module (`from`/`format`/`fromEther`/`fromGwei`/
`formatEther`/`formatGwei`), which rounds exactly in decimal space, and
adds regression tests for the reported cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5AhB5FfyPaJLykDnV8Eqi
@changeset-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 23280a7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
viem Error Error Jul 18, 2026 1:12am

Request Review

@jxom
jxom merged commit cb4bd8f into main Jul 18, 2026
5 of 8 checks passed
@jxom
jxom deleted the claude/viem-4855-ox-value-2r9jku branch July 18, 2026 01:11
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(...))

2 participants