Skip to content

Instantly share code, notes, and snippets.

@Neurone
Created January 20, 2018 15:38
Show Gist options
  • Save Neurone/2bc9d2f108c709b60bf39f19ef6f49a8 to your computer and use it in GitHub Desktop.
Save Neurone/2bc9d2f108c709b60bf39f19ef6f49a8 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.19;
contract DecimalsTest {
uint256 public decimals256;
uint256 public totalSupply256_AsExpected_1;
uint256 public totalSupply256_AsExpected_2;
uint8 public decimals8;
uint256 public totalSupply256_Unexpected_1;
uint256 public totalSupply256_Unexpected_2;
uint256 public decimals256_Unexpected_1;
uint256 public decimals256_Unexpected_2;
function DecimalsTest() public {
uint256 _decimals256 = 18;
uint8 _decimals8 = 18;
uint256 _initialSupply256 = 500000;
// memory
totalSupply256_AsExpected_1 = _initialSupply256 * (10 ** _decimals256);
// same result with storage
decimals256 = _decimals256;
totalSupply256_AsExpected_2 = _initialSupply256 * (10 ** decimals256);
// memory
totalSupply256_Unexpected_1 = _initialSupply256 * (10 ** _decimals8);
// same result with storage
decimals8 = _decimals8;
totalSupply256_Unexpected_2 = _initialSupply256 * (10 ** decimals8);
// memory
decimals256_Unexpected_1 = 10 ** _decimals8;
// same result with storage
decimals256_Unexpected_2 = 10 ** decimals8;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment