I know that Solidity doesn't use decimals, but I'm having a hard time wrapping my head around 18 zeros in Wei in calculating compound interest. How do you do it? I have found no examples.
I first tried this:
contract CompoundInterest {
uint public Periods = 30;
uint public Principle = 10000;
uint public Interest;
uint public InterestRateInteger = 2;
function CalculatedInterest() public {
Interest = Principle * (1 + InterestRateInteger/100)**Periods;
}
This example is just the classic compound interest formula. I tried this as well, and got a result that was correct, but I couldn't figure out how to refactor for Wei.
function CalculatedInterest() public {
Interest = Principle * (100 + InterestRateInteger)**Periods;
}
The idea is that interest only compounds years, so 102 would be equal to 1.02.