How to avoid calculation mistakes with primitives
<p>The following routine is expected to return <strong>1</strong>, but instead it returns <strong>0.9999999999999999</strong>. </p>

<pre><code>double sum = 0;
for(int i=0; i&lt;10; i++){
    sum+=0.1;
}
System.out.println(sum);
</code></pre>

<p>The same mistake occurs also with other java mathematical operations.</p>

<p>Is there any way to avoid this issue?</p>

<p>Thank you in advance.</p>