Hey guys, I'm new to solidity arithmetics, can someone explain how I can fix an inaccuracy that I have encountered? I have calculated values in a Java program separately from solidity smart contract and got different results...
Solidity values:
uint T = 700000000000000000
uint S = 27469624011473289402
uint HUNDRED_PERC = 1000000000000000000
uint A = T.mul(HUNDRED_PERC).div(S);
Java output (expected): 26149041155751178
Solidity output: 25482693163460471
The breakdown of Solidity calculation:
uint A =
T.mul(HUNDRED_PERC) = 700000000000000000000000000000000000
700000000000000000000000000000000000.div(S) = 25482693163460471
So, it's the div() operation that results in in accuracies...
Do you know how to fix this? I'm using SafeMath