Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Error in comparing two double values in C++ Builder

Avatar of Chrysaor
Chrysaor asked on
C++Editors IDEs
4 Comments1 Solution510 ViewsLast Modified:
I've created an application , and I have two classes, let's name them ClassA , ClassB, and two objects respectively, ObjectA , ObjectB. In each class, I've created a public double, e.g doubleA, doubleB. Somewhere in the application, doubleA gets a value, e.g 0.15 and doubleB gets a value also. At some point, I try to compare both these doubles. And there is a very strange error. The first statement I use, is if (ObjectA.doubleA > ObjectB.doubleB) {.... return } , which if true ,always works . The next statement is :  if (ObjectA.doubleA == ObjectB.doubleB) {.... return }  and the third is : if (ObjectA.doubleA < ObjectB.doubleB) {.... return } . But, if the doubleA is indeed equal to doubleB, it doesn't recognise it, and it moves to the third statement which finds true (which is not!). In order to test this, I write each time the values of doubleA and doubleB in a txt file, and indeed, it says doubleA is 0.15, doubleB is 0.15 , but still, doesn't recognize the == statement , and moves forward and recognizes the < statement! Why that thappens? Is thit possible that there is a third digit (e.g 0.153 < 0.157) which is not shown it the text file? Thanks a lot.
ASKER CERTIFIED SOLUTION
Avatar of jkr
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers