I want to introduce transaction fees. I would like to take 0.5% of the msg.value. So whenever a user calls this function I want to assign a variable the 0.5% of the msg.value

1 Answer 1


Just divide by 200.

uint256 fee = msg.value / 200;

And there is no floating point in solidity, so you get uint256 as a result, and the division result rounds towards zero.

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.