Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.18;
- contract MathTests {
- uint month = 30 days;
- uint endTime = now + month;
- uint punishTime = now + (endTime-now)/2; // simulating that punished occured half way the subscription
- uint startTime = now;
- function getDivided(uint numerator, uint denominator) public constant returns(uint quotient, uint remainder) {
- quotient = numerator / denominator;
- remainder = numerator - denominator * quotient;
- }
- 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);
- }
- // 8 tokens => return 4 (punish time is 1/2)
- function precentFixed() public view returns(uint){
- uint tokens = 8;
- uint pre = tokens * percent(punishTime - startTime,endTime - startTime,2);
- uint res = pre / 100;
- return res;
- }
- }
Add Comment
Please, Sign In to add comment