I'm trying to make some advanced calculations in Solidity. I was able to successfully implement the algorithm on my contract, but its results are way below zero, and whenever I try to get it with Javascript, it justs rounds down to 0. Is there any way I can multiply a fraction stored in a variable by a really big number so I can get some precision here? Example:

uint256 x = uint256(5)/uint256(10);

and then:

x *= 100;

resulting in:

> x = 50 <

And here is some of the code I implemented:

enter image description here


1 Answer 1


Because the EVM deals only with integers, 5/10 = 0. Subsequent multiplication is irrelevant.

Change the order of operations so division comes last and consider this idea for decimals of precision, if needed. Can't do any integer division

Hope it helps.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.