0

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); }

2 Answers2

0

You can take a look at a workaround for calculations using decimal numbers:

https://github.com/ethereum/solidity/issues/3200

Yongjian P.
  • 4,170
  • 1
  • 3
  • 10
0

A workaround might be multiplying by 10^n and returning this result. In the application you can divide it by / 10^n.