I need to calculate values for percentage and I need them to have two decimal places and the minimum value is 0.00 and the maximum value is 100.00.
When I use some decimal place, for example: 80.01 the compiler complains saying that I have to change to ufixed, but I saw that it is not supported.
What is the correct way to approach this contract?
CONTRACT
struct Vote {
uint total;
uint totalPercentage;
}
Vote private _abstentionVotes;
uint private _totalElectoresVoted;
constructor() {
_abstentionVotes.total = 0;
_abstentionVotes.totalPercentage = 0.00;
_totalElectoresVoted = 0;
}
function _calculePercentageOfVote(uint totalVotes) private view returns (uint) {
return ((totalVotes / _totalElectoresVoted) * 100);
}