I've just learned a lot about Solidity and decided to put it into practice. Something I truly don't understand is how I can bypass the limitations of this programming language.
Assume the following scenario:
We have some sort of ICO where users exchange their altcoins for our own coin, for instance CoinA.
Today CoinA = $1
Tomorrow we set CoinA = $1.5
After-tomorrow we set CoinA = $1.75
Let's assume for now that altcoins have a stable value:
Altcoin1 = $0.222
Altcoin2 = $0.7
The problem I have is that solidity doesn't allow us to use decimals. Answers that I found say to use all of the 18 decimals that Ethereum offers however I'm truly confused about that. Nobody shows a way to implement in a practical scenario.
Consider the following code:
pragma solidity ^0.4.24;
contract Ballot {
uint256 icotokenPrice;
mapping(string => uint256) tokensPrice;
function assignICOPrice(uint256 _tokenPrice) public returns(bool){
icotokenPrice = _tokenPrice;
return true;
}
function createTokenPrice(string symbol_, uint256 price_) public returns(bool){
tokensPrice[symbol_] = icotokenPrice / price_;
return true;
}
function returnPrice(string symbol_) public view returns(uint256){
return(tokensPrice[symbol_]);
}
}
Brief description
assignICOPrice function allows us to manually assign "CoinA" from $1 to $1.5, to $1.75. The problem we have is that we can't do anything after . since uint256 are integers. How do we solve this problem?
createTokenPrice allows us to define the AltcoinPrice. For example, for Altcoin1 = $0.222 and for Altcoin2 = $0.7
Any proper solution to bypass this issue? I also tried to read EtherDelta's smart contract but it doesn't seem to have anything like that.