Solidity根据精度来表示浮点数

https://stackoverflow.com/questions/42738640/division-in-ethereum-solidity/42739843

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

}

 

转载于:https://www.cnblogs.com/huahuayu/p/9219498.html

你可能感兴趣的:(Solidity根据精度来表示浮点数)