I've looked into the following answers, but have not found what I am looking for.
Any help is appreciated.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI've looked into the following answers, but have not found what I am looking for.
Any help is appreciated.
As seen in SO copying and pasting shamelessly to keep the users here.
It's probably best (lowest gas cost and trivial to implement) to perform that calculation on the client rather than in Solidity.
pragma solidity ^0.4.6;
contract Divide {
function percent(uint numerator, uint denominator, uint precision) public
constant returns(uint quotient) {
// caution, check safe-to-multiply here
uint _numerator = numerator * 10 ** (precision+1);
// with rounding of last digit
uint _quotient = ((_numerator / denominator) + 5) / 10;
return ( _quotient);
}
}
If you feed it 101,450, 3 you get 224, i.e. 22.4%.