Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixedNumber.round() throws incompatible format on non-default formats #1629

Closed
zedkai opened this issue May 30, 2021 · 3 comments
Closed

FixedNumber.round() throws incompatible format on non-default formats #1629

zedkai opened this issue May 30, 2021 · 3 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@zedkai
Copy link

zedkai commented May 30, 2021

Describe the bug
Rounding numbers which are not of the default format results in an incompatible format error.

Reproduction steps

FixedNumber.fromValue(1, 27, "fixed256x27").round()

Error produced:

Uncaught Error: incompatible format; use fixedNumber.toFormat (argument="other", value={"format":{"signed":true,"width":128,"decimals":18,"name":"fixed128x18","_multiplier":"1000000000000000000"},"_hex":"0x0de0b6b3a7640000","_value":"1.0","_isFixedNumber":true}, code=INVALID_ARGUMENT, version=bignumber/5.1.1)
  makeError index.ts:205
  throwError index.ts:217
  throwArgumentError index.ts:221
  _checkFormat fixednumber.ts:211
  mulUnsafe fixednumber.ts:230
  round fixednumber.ts:283
  <anonymous> debugger eval code:1

Environment:
Browser JS context.

Search Terms
FixedNumber, round, rounding

@zedkai zedkai added the investigate Under investigation and may be a bug. label May 30, 2021
@ricmoo
Copy link
Member

ricmoo commented May 30, 2021

Thanks! That looks like a bug on my side. I’ll look into this shortly.

@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels May 30, 2021
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Jun 1, 2021
@ricmoo
Copy link
Member

ricmoo commented Jun 1, 2021

This should be fixed in 5.3.0. Try it out and let me know if you still have any issues.

Thanks! :)

pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
@ricmoo ricmoo closed this as completed Jun 11, 2021
@alexanderwende
Copy link

Hi, I think there's still a small bug in there, when working with negative numbers...

Describe the bug

Rounding negative numbers which are not of the default format results in an incompatible format error.

Reproduction steps

FixedNumber.from('-0.01101100205516751', 'fixed128x17').round(2)

Error produced

Uncaught Error: incompatible format; use fixedNumber.toFormat (argument="other", value={"format":{"signed":true,"width":128,"decimals":18,"name":"fixed128x18","_multiplier":"1000000000000000000"},"_hex":"0x0de0b6b3a7640000","_value":"1.0","_isFixedNumber":true}, code=INVALID_ARGUMENT, version=bignumber/5.4.0)
    at Logger.makeError (index.ts:213)
    at Logger.throwError (index.ts:225)
    at Logger.throwArgumentError (index.ts:229)
    at FixedNumber._checkFormat (fixednumber.ts:217)
    at FixedNumber.subUnsafe (fixednumber.ts:229)
    at FixedNumber.floor (fixednumber.ts:257)
    at FixedNumber.round (fixednumber.ts:294)

Environment

browser

Notes

When removing the minus sign from the number, no error is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

3 participants