NormalizeDouble question

 

Hi,

I just finish a couple of days in hell. I was debugging a piece of code and used prints and alerts everywhere . Then I realised something very "funny":

This is what I did and the results are driving me crazy.

   double normAsk=NormalizeDouble(Ask,Digits);
   string string_normAsk=DoubleToStr(Ask,10);
   double str_to_dbl_normalizedAsk=StrToDouble(string_normAsk);
   
   Alert("digits=",Digits," ask=",Ask," normAsk=",normAsk," string_normAsk=",string_normAsk," str_to_dbl_normalizedAsk=",str_to_dbl_normalizedAsk);
   Print("digits=",Digits," ask=",Ask," normAsk=",normAsk," string_normAsk=",string_normAsk," str_to_dbl_normalizedAsk=",str_to_dbl_normalizedAsk);
  

This is the results:

2010.08.26 10:49:46     2008.10.31 16:00  Fisher_Crossing_EA EURUSD,M15: digits=5 ask=1.2716 normAsk=1.2716 string_normAsk=1.27157000 str_to_dbl_normalizedAsk=1.2716
2010.08.26 10:49:46     2008.10.31 16:00  Fisher_Crossing_EA EURUSD,M15: Alert: digits=5 ask=1.2716 normAsk=1.2716 string_normAsk=1.27157000 str_to_dbl_normalizedAsk=1.2716

If you see in the output, Ask and normalized Ask have the same values. Only after you convert it to string you can see it. So, my questions are:

What are the real values(outside the print or alert statements) of Ask after use NormalizeDouble function? 1.2716 or 1.2716.......

So, if you use print or alert to check the results after using NormalizeDouble function you will never see it unless you convert it to string. Am I right? Is it there another way to "debug" without using print or alert? and finally, Will this happens with any other function in MT4 or just in print or alert statements?

Thanks.

FAC in Orlando, FL

 

The EA will will "see" the correct value regardless of print and alert. These functions truncate to 4 decimal places for display purposes only. As you say, the way around this if you want to print better precision is doubletostr.

V

V

 
Viffer:

The EA will will "see" the correct value regardless of print and alert. These functions truncate to 4 decimal places for display purposes only. As you say, the way around this if you want to print better precision is doubletostr.

V

V


Thanks V,

The answer was also here:

https://www.mql5.com/en/forum/122500, but thanks a million anyway.

FAC

Reason: