-3

hi folks i'm looking do do the following division function here is an example of the input.

_value / (totalSupply() / _shareSupply);

50000000000000000000 / 110000000000000000000 / 100000000000000000000

2
  • 2
    Did you have a question?
    – user19510
    Jan 9, 2019 at 6:00
  • 1
    There is no clear question in this post
    – Webdev
    Jan 9, 2019 at 7:32

1 Answer 1

1

Some things you should take into account when doing this:

  • Solidity doesn't at the moment have support for floating point arithmetic, so expect rounding
  • There may be other ways of achieving the same outcome
  • Where possible, try and turn division into multiplication, so that you are not affected by rounding errors

If you have to arrive at this ratio, I would propose the following formula:

_value * _shareSupply / totalSupply().

However, if you are, for example checking if this value is greater than some value x, it's better achieved like so:

_value * _shareSupply > x * totalSupply()

Do keep potential overflow risks in mind depending on the maximum size of numbers.

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