i have a token swap contract that does simple operation, TokenA is 150% of value of TokenB

so if i swap 5 of TokenA i get 7.5 of TokenB

the problem is that solidity doesn't accept floating point numbers so how do i get accurate result of the following operation

        uint256 exchangeAmount = uint256(((100 / ratio) * 100)) * amount) / 100
    ) - fees;

if 100/ratio is less then 1, solidty will automatically round that value to zero and i would get erroneous values, how do i solve this problem?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.