Can somebody explain why double is being treated differently in the following code piece ? double d1= 33.30+33.40+33.30; double d2= 33.40+33.30+33.30; double d3= 33.30+33.30+33.40; Among these only d3 gives me result of 100.0 other 2 gives me 99.9.
Jean-Sebastien is, of course, absolutely right. The key two points are:
1. Floating point math is an *approximation* (integer and BigDecimal is *exact*) ... and ... 2. The order you perform the individual calculations affects what values the intermediate results round to, which in turn affects the final result.
Paul M. Santa Maria, SCJP
Joined: Aug 10, 2005
Thanks to both of you !!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com