Hello, this is probably more mathematical question than solidity, but I will ask anyway. For example reward is 9. In smart contract I calculate rewardPerToken = 0 + (9 / 42) = 0.214285714285714285. Then I calculate based on that how much of reward each staker gets based on how much they are staking. For example first user has 10 tokens, so he gets - 10 * 0.214285714285714285 = 2.14285714285714285. Ok, now second user holds 32 tokens, so he gets - 32 * 0.214285714285714285 = 6.85714285714285712. If I add those results together I get - 6.85714285714285712 + 2.14285714285714285 = 8.99999999999999997, but in reality it should be 9? So there is 0,00000000000000003 tokens "lost in space". Any clue how to avoid that? :man_shrugging:
Sep 23, 2022, 4:20 PM
You truncated 9/42 to 18 decimals, that's where its lost
Welcome to rounding
Sep 23, 2022, 5:13 PM
I know that, but how to solve that?
Sep 23, 2022, 5:23 PM
No sure shot solution, you have to round it at some point
18 decimal precision is pretty decent if you ask me
Sep 23, 2022, 5:55 PM