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

}

 

posted @ 2018-06-24 05:11  huahuayu  阅读(722)  评论(0编辑  收藏  举报