Guest User

Untitled

a guest
Feb 13th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2. contract MathTests {
  3. uint month = 30 days;
  4. uint endTime = now + month;
  5. uint punishTime = now + (endTime-now)/2; // simulating that punished occured half way the subscription
  6. uint startTime = now;
  7. function getDivided(uint numerator, uint denominator) public constant returns(uint quotient, uint remainder) {
  8. quotient = numerator / denominator;
  9. remainder = numerator - denominator * quotient;
  10. }
  11. function percent(uint numerator, uint denominator, uint precision) public constant returns(uint quotient) {
  12. // caution, check safe-to-multiply here
  13. uint _numerator = numerator * 10 ** (precision+1);
  14. // with rounding of last digit
  15. uint _quotient = ((_numerator / denominator) + 5) / 10;
  16. return ( _quotient);
  17. }
  18. // 8 tokens => return 4 (punish time is 1/2)
  19. function precentFixed() public view returns(uint){
  20. uint tokens = 8;
  21. uint pre = tokens * percent(punishTime - startTime,endTime - startTime,2);
  22. uint res = pre / 100;
  23. return res;
  24. }
  25.  
  26. }
Add Comment
Please, Sign In to add comment