Replies: 1 comment
-
the usual pattern for doing decimals math with integer is to using a scaling factor:
this example would have zero fees for values between E-8 and E-4, if thats an issue you could play around with rounding, a different scaling factor or using u128 for scaling you could also using trying |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Discord user ID
ibuidl
Describe your question in detail.
Let's say I have an amount of coins (ex: 1 APT) and I want to calculate the percentage of fees (1%).
So the value is 0.01 APT. I'm using math64 to calculate the percentage:
use aptos_std::math64;
let fees = math64::mul_div(amount, 1, 100)};
The issue is that mul_div returns an u64. So the value of fees will be 0 instead of 0.01.
And here I'm not withdrawing anything:
let coin = coin::withdraw<AptosCoin>(account, fees);
(I guess APT has 8 decimals so we can do a workaround with but I don't know how. Is there a solution for this?)
What error, if any, are you getting?
No response
What have you tried or looked at? Or how can we reproduce the error?
No response
Which operating system are you using?
macOS
Which SDK or tool are you using? (if any)
Aptos CLI
Describe your environment or tooling in detail
No response
Beta Was this translation helpful? Give feedback.
All reactions