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

ethers.utils.parseUnits validity problem with inputs with trailing zeros #2016

Closed
arkantos1482 opened this issue Sep 7, 2021 · 6 comments
Closed
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@arkantos1482
Copy link

arkantos1482 commented Sep 7, 2021

Describe the bug
when using ethers.utils.pareUnits method for numbers with trailing zeros, (which is the case when you format numbers with specific decimal points),when unitName being lesser than the decimal places, the result number would be to some extent arbitrary. for instance:

sometimes it is ten times bigger
ethers.utils.parseUnits("0.242551", 6) = 0x03b377 => which is 242551
ethers.utils.parseUnits("0.2425510", 6) = 0x2502a6 => which is 2425510

sometimes it is completely arbitrary:
ethers.utils.parseUnits("2.516659", 6) = 0x2666b3=> which is 2516659
ethers.utils.parseUnits("2.5166590", 6) = 0x6d5a7e=> which is 7166590

Reproduction steps
import {ethers} from 'ethers'
console.log(ethers.utils.parseUnits("2.516659", 6))
console.log(ethers.utils.parseUnits("2.5166590", 6))

Expected behavior
raising exception when input value is not valid

@arkantos1482 arkantos1482 added the investigate Under investigation and may be a bug. label Sep 7, 2021
@ricmoo
Copy link
Member

ricmoo commented Sep 16, 2021

You are right! This does seem like a bug. Investigating it now.

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. labels Sep 16, 2021
@ricmoo
Copy link
Member

ricmoo commented Sep 16, 2021

This has been fixed in 5.4.7. Please try it out and let me know if you have any problems.

Thanks! :)

@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 Sep 16, 2021
@ChALkeR
Copy link

ChALkeR commented Sep 17, 2021

Is this the same as #1974 or different?

@ricmoo
Copy link
Member

ricmoo commented Sep 17, 2021

@ChALkeR I believe it should be the same. I’ll double check and tag that issue with the commit and related issues.

@ChALkeR
Copy link

ChALkeR commented Sep 17, 2021

See also a comment here: 32a6b2a#r56633460 )

@arkantos1482
Copy link
Author

Thanks,
with some use cases I tested upon, it worked correctly.

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