This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 796
Possibly wrong implementation of "format_units" #168
Labels
bug
Something isn't working
Comments
This should be fixed in #170 @PaulRBerg! |
hey just doing my first steps with rust and I think there might still be an issue:
|
@gakonst can you reopen this issue since it's still not correct? |
i think this was addressed in #463? |
I have modified the parse_unit test to show that if you have 18 decimal places some are lost since f64 doesn't have enough bits to hold such a high precision number. |
I can submit a pull request with a fix but it will have to use the rug crate (https://crates.io/crates/rug) to create a float larger than 64bit. |
@gakonst have you had a chance to look at the modified test? |
+1 on the test and fixing it by using |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Description
I was looking to use the format-units function, part of
ethers-core::utils
. I was expecting the same behaviour as in the canonical ethers.js, but theformat_units
function behaves differently in ethers-rs.Actual Behaviour
Take the following Rust code:
This logs the following:
Expected Behaviour
Take the following JavaScript code:
This logs the following:
Which is correct, as per the identity 1 eth = 1e9 gwei = 1e18 wei.
Possible Solution
Rewrite the format_units function to divide by
10^(decimals)
instead of justdecimals
.Environment
Using [email protected]
The text was updated successfully, but these errors were encountered: