I am trying to write a presale contract as an exercise that would allow the deployer to collect ether from buyers, then redistribute the amount of tokens proportionately to the amount spent by the buyers over the totalAmount of ether spent during the presale.
the function to calculate the token amounts to be sent to each buyer looks like this :
function _calculateClaim(address _claimer) public view returns(uint256) {
//amount paid in wei by user
uint256 amountPurchased = presalePayment[_claimer];
//trying to obtain a ratio number 0.xxx to the total amount of eth received
uint256 totalShare = amountPurchased.div(totalPaymentReceived);
//this would give me the number of tokens to send to the address relative to the total of tokens that need to be redistributed
uint256 allowedAmount = totalShare.mul(presaleAmount);
return(allowedAmount);}
obviously totalShare canno't store a decimal value and is returned as a 0. Is there a simple workaround for this issue? what type of variable should i assign to totalShare?
thanks