File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes program gives different results with same data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "program gives different results with same data" Watch "program gives different results with same data" New topic

program gives different results with same data

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
I make program which do some manipulation on data from dataase and return a double value. It works fine there is no error .Problem is that with same data it gives different output .I can't understand it because logic is same ,data is same then why it produce different result .In my program i do calculation on double and then add all the previous double .I also use Double object .Is changing from string to Double object or double and adding all this figures will it give me different result.Is using d.doubleValue gives different result .
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Could be a phase of the moon issue.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
if its floating point it oculd be a rounding error, try using strictfp/StrictMath
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If you add the same floating-point numbers in different orders, it's possible to get different answers. But they normally won't be significantly different, unless the numbers vary considerably in size.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Does your program use multiple threads at all? Behavior such as you describe is often a sign of problems with threading.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: program gives different results with same data
It's not a secret anymore!