Skip to content

fix: reject negative FixedNumber decimals#5130

Open
fuyua9 wants to merge 1 commit into
ethers-io:mainfrom
fuyua9:fix/reject-negative-fixed-decimals
Open

fix: reject negative FixedNumber decimals#5130
fuyua9 wants to merge 1 commit into
ethers-io:mainfrom
fuyua9:fix/reject-negative-fixed-decimals

Conversation

@fuyua9

@fuyua9 fuyua9 commented Apr 25, 2026

Copy link
Copy Markdown

Summary

  • reject negative FixedNumber decimal counts before they reach fixed-point scaling helpers
  • cover negative decimals for formatUnits, parseUnits, FixedNumber.fromValue, and object-form FixedNumber.fromString formats

Why

FixedNumber formats already reject decimals above 80, but object-form formats could still pass negative decimals through. That can produce confusing behavior in callers such as unit conversion, where a negative numeric unit is not a meaningful decimal count. This change makes negative decimals fail with the same argument-validation path used by other invalid fixed formats.

Validation

  • npm ci
  • npm run build -- --pretty false
  • ./node_modules/.bin/mocha --trace-warnings --reporter ./reporter.cjs ./lib.esm/_tests/test-utils-units.js --grep "negative decimal|bad unit conversion"

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.

1 participant