Last active
June 13, 2018 08:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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