0

How would i work out "x is what percent of y" or for example 5 is what percent 10 = 50%. For some reason i just cant wrap my head around it.

A clip of my code is below, i want to work out balanceOf[msg.sender] is what percent of totalCrowdFund.

 uint256 public totalCrowdFund;
bool refundStatus;

mapping(address => uint256) public balanceOf;
mapping(address => bool) public emergencyRefundStatus;

constructor() {
    owner = msg.sender;
    totalCrowdFund = 0;
}

1 Answer 1

0

I suspect that the percentages can be very small, so the formula is as follows:

uint256 res = balanceOf[owner] * 100000 / ( totalCrowdFund);

where the result is 1/1000 percent. That is (res = 267) == 0.267%

1
  • I appreciate it !!!! Commented Apr 25, 2022 at 16:05

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.