I'm trying to implement staking into a project. Lets say my contract has a balance of 1000 erc20 tokens, which during the calculation is actually 1000000000000000000000 because of wei. If i know user A has provided 255 of that 1000, user A is entitled to 25.5% of any profits. Lets pretend the profits are also 1000 eth of an erc20 token. How do I represent 25.5% since solidity only uses integers, and how do i then send 25.5% of 1000000000000000000000, which I know will not be a whole number?

1 Answer 1


For example, you represent a percentage in the form of thousandths:

a_proc=(a_stake*1000)/a_sum ;
b_stake=(a_proc*b_sum)/1000 ;

Or directly:

b_stake=(a_stake*b_sum)/a_sum ;

You will lose the fractional part of wei, but it is a VERY small value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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