0

I am running into some issues trying to convert this equation into solidity friendly code

x * (0.933333 + y/z/3.75)

I've tried converting values in the following way, but end up w/ incorrect results. Any ideas?

uint y = 2294;
uint z = 1293;
uint a = 0.93333 * 10 ** 18;
uint b = y / z * 10 ** 18;
uint c = 3.75 * 10 ** 18;
0

Solidity's support for decimal numbers is basically non-existing. Therefore you can't use decimal numbers in Solidity.

What you need to do is first convert it the number to an integer, for example uint a = 93333 * 10 ** 13. Do the same for all your decimal numbers.

Assuming you need the real result in the end (or, more like it, a rounded integer version of it), you can just divide by 10**18.

3
  • That's what I am doing
    – pizzarob
    Jan 12 at 23:18
  • No, you are using explicit decimal places in your numbers Jan 13 at 8:50
  • Just to clarify, I'm showing how I convert the decimals at the bottom of my question. The issue was dividing by 3.75 - even if I converted via 10 ** 18 it would be incorrect because y and z divide first and had already been converted. So I did uint b = y * 10 ** 18/z; uint c = (b / 375) * 100;
    – pizzarob
    Jan 14 at 22:02

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.