Comparsion Problem

 

Hello,

i try to compare two double numbers with the same values but the querie is false

Code:

double a,b;

a=High-Open; //The Result is 0.0001

b=1.3333-1.3332; //The Result is 0.0001

if(a==b)Print("true"); //Result is false

if(a>b)Print("true"); //Result is true

if(a<b)Print("true"); //Result is false

What ist the problem please, why does this dont match?

How is the solution?

 
echnaton:
Hello,

i try to compare two double numbers with the same values but the querie is false

Code:

double a,b;

a=High-Open; //The Result is 0.0001

b=1.3333-1.3332; //The Result is 0.0001

if(a==b)Print("true"); //Result is false

if(a>b)Print("true"); //Result is true

if(a<b)Print("true"); //Result is false[/code]What ist the problem please, why does this dont match?

How is the solution?

How would you even know which result you are getting? Regardless of the result, this script will print "true". [code] if(a==b)Print("true"); //Result is false

else if(a>b)Print("true"); //Result is true

else if(a<b)Print("true"); //Result is false

Try this.

 

Hello,

i have tried it before by write numbers to the printing result, sorry that i dont have tell it, i forgot.

now with this code:

double a,b;

a=High-Open; //The Result is 0.0001

b=1.3333-1.3332; //The Result is 0.0001

if(a==b)Print("1 true"); //Result is false

else if(a>b)Print("2 true"); //Result is true

else if(a<b)Print("3 true"); //Result is false[/CODE]

you can see what is printing, its "2 true" a>b , crazy, because aand b are the same double values 0.0001

i have do other test

[CODE]

if(Point==a) //result false

if(Point==b) //result false

if(a==0.0001) //result false

if(b==0.0001) //result false

if(Point==0.0001) //result true

so the Konstant Point is like normal double value 0.0001.

the double values from calculating in a and b are not same with Point or 0.0001.

But if you Print(" ",a," ",b," ",Point); you get the same values seen which are 0.0001

 

First of all, how do you know that High - Open equals 0.0001?

But, if the difference is indeed exepected to be 0.0001, it may internally be something like 0.00010000001, which is different from 0.0001, and which would make a > b true. So what you may want to try is use NormalizeDouble(), which rounds a number to a given number of decimals. For example:

double a,b;

a=NormalizeDouble(High-Open, 4); //The Result is 0.0001

b=1.3333-1.3332; //The Result is 0.0001

if(a==b)Print("1 true");

else if(a>b)Print("2 true");

else if(a<b)Print("3 true");
 
zuijlen:
First of all, how do you know that High - Open equals 0.0001?

I have adjust it so with queries that the wished prices come in.

Thank you very much for your well explanation you are right and know it works with the function NormalizeDouble() i am happy to know this now to, god bless you all :-).

Reason: