Skip to content

Instantly share code, notes, and snippets.

@rolandkofler
Last active June 13, 2018 08:40
Show Gist options
  • Save rolandkofler/cb9e91d948986c69b498626c8bb5fb72 to your computer and use it in GitHub Desktop.
Save rolandkofler/cb9e91d948986c69b498626c8bb5fb72 to your computer and use it in GitHub Desktop.
Shows that a single computation preserves the decimals while a multistep computation not
pragma solidity 0.4.24;
import 'https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol';
contract TestDecimals{
uint public singleComputation;
uint public multiStepComputation;
uint public safeMath;
using SafeMath for uint;
constructor(){
singleComputation = (123456 / 100 + 1) * 100;
uint t1 = 123456;
t1 = t1 / 100;
multiStepComputation = (t1 + 1) * 100;
safeMath = uint(123456).div(100).add(1).mul(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment