This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.

Try follow coding. Guess what's the output? int size = 55; double total = 0.0; for (int i = 0; i < size; i++) { total += 0.1 + i; } System.out.println("Total is : " + total); The answer is "Total is : 1490.4999999999995" Any ideas about fixing the problem except using BigDecimal?

I have to assume that the problem is the rounding issue. doubles and floats both have decimals. In order to be precise with decimals you would need to have an infinite number of decimal places (of course impossible) therefore they are ALWAYS not quite exact. BigDecimal is probably your best bet.

"JavaRanch, where the deer and the Certified play" - David O'Meara