-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Comments
You are right! This does seem like a bug. Investigating it now. |
This has been fixed in 5.4.7. Please try it out and let me know if you have any problems. Thanks! :) |
Is this the same as #1974 or different? |
@ChALkeR I believe it should be the same. I’ll double check and tag that issue with the commit and related issues. |
See also a comment here: 32a6b2a#r56633460 ) |
Thanks, |
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
The text was updated successfully, but these errors were encountered: