0

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

Thanks.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145

1 Answers1

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.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145