JAVA floating point operations
<p>I'm doing a lot of floating point operations in my application, and I'm aware that floating point operations are not 100% accurate which is fine but when it comes to printing the result I have yet to find a way to format it properly.</p>

<p>for example</p>

<p>0.1 + 0.1 = 0.19999999999999999999999</p>

<p>Math.sin(Math.PI) = 1.2246E16 instead of 0</p>

<p>and stuff like 1.000000000000000001 </p>

<p>I'm looking for a general way to take those results and get the proper rounded value (in a String form)</p>

<p>so that
0.1 + 0.1 = 0.19999999999999999999999 -> 0.2  this one requires rounding up</p>

<p>Math.sin(Math.PI) = 1.2246E16 -> 0</p>

<p>and stuff like 1.000000000000000001 -> 1     ; while this one requires rounding down</p>

<p>I'd also like to avoid losing data in cases like when the result is
1.1234567891234567 or 1.33333333333333 in those cases the result should remain the same.</p>
