daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top