In Solidity division can result in rounding down errors, hence to minimize any rounding errors we always want to perform multiplication before division.
In above code we can see the priceEurUsd
will divides afterwards it will multiplied by _hundredPC
this will make less precision than expected.
Take a scenario :-
price = 8965
rate = 20
Output
DivBefore = 1780
multiplyBef = 1793
We can observe multiplyBef
gives accurate output but DivBefore
gives -13. Solidity doesn't support floating points.
By doing the division before multiplication leads to rounding issues.
Manual View
We can make division after multiplication which can mitigate rounding related issues as much as possible. The computations can be much more complex and forming them into a multiplication first formula can be challenging at times
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.