-
-
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
formatUnits always generates trailing .0
#1291
Comments
The This makes it easier to re-format the string, without needing complex logic. So, for your case you could use I suppose |
Actually, quick note. in v6, it will do this only when |
I've added this to my active todo list for v6, so I'm going to close this here. Thanks! :) |
Adding this to the next minor bump, actually. :) |
This has been addressed in 5.2.0. Please let me know if you still have any issues. Thanks! :) |
ethers.utils.formatUnits(ethers.utils.parseUnits('1', 18), 18);
// 1.0 I think display just like Even if it is a float number, it can be an integer when there is no fractional part. |
Keep in mind The reason for the string representation for |
Thanks for your reply, but I also think we can try it just like parseFloat('1.000000000').toFixed() // 1
parseFloat('1.000000000').toFixed(1) // 1.0
parseFloat('1.000000000').toFixed(2) // 1.00 ethers.utils.formatUnits(ethers.utils.parseUnits('1', 18), 18); // 1.0
ethers.utils.formatUnits(ethers.utils.parseUnits('1', 18), 18, shortMode=true); // 1 |
|
It's not nice being required to @Ric couldn't it just be an optional parameter where we define decimal precision expected? Could be "1" by default for backwards compatibility. Like @lomocc suggested above, but I'd think of something like this:
Alternatively, instead of fixed precision, the parameter could be "maxPrecision", so:
|
Do I have to remove it manually or is there a flag not to generate it ?
I'd love to just get
1
vs1.0
The text was updated successfully, but these errors were encountered: