I'm making a calculator using Java. It's all working and I'm now trying to implement decimals. I'm using doubles to store the numbers. I have a solution the following solution:
decPoints++; //decPoints holds the current number of numbers after the decimal point
currentVal = currentVal + (n/Math.pow(10, decPoints)); //n is the number that is to be added on
This works, however it results in rounding errors e.g. 3.369 would become 3.689999..
Is there an easy solution to this problem or another way to implement decimals?
Thanks in advance!