Double multiplication bug?

 

Hi, very strange behaviour is found:

 

#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   double LocalLots = -0.03;
   double RemoteLots = -0.02;
   
   
   RemoteLots=NormalizeDouble(RemoteLots,2);
   LocalLots=NormalizeDouble(LocalLots,2);

   Print("LocalLots * RemoteLots = ",LocalLots*RemoteLots);    // returns 0.0006
   Print("LocalLots * RemoteLots = "+DoubleToStr(LocalLots*RemoteLots,5));    // prints  0.0006
                            l("#2 -"+DoubleToStr(LocalLots*RemoteLots,5));    // prints -0.0006
   

   Print("LocalLots * RemoteLots = "+DoubleToStr((LocalLots*RemoteLots),5));    // prints  0.0006
                            l("#3 -"+DoubleToStr((LocalLots*RemoteLots),5));    // prints -0.0006

   double x = LocalLots * RemoteLots;
   Print("x = "+DoubleToStr(x,5));                                              // prints 0.0006
                            l("#4 -"+DoubleToStr(x,5));                         // prints -0.0006
   

   l("------------");
   
   
  }
//+------------------------------------------------------------------+
void l(string line) { Print(line);}
//+------------------------------------------------------------------+

 

 

 

I hope this is clear and helps to sort out the issue.

All results should be 0.0006 but as soon i pass the string to a function it seems to have serious bug. This might cost us big trouble! Build 670. Same behavious on 646 too. 

 
fx1.net:
...

I hope this is clear and helps to sort out the issue.

All results should be 0.0006 but as soon i pass the string to a function it seems to have serious bug. This might cost us big trouble! Build 670. Same behavious on 646 too. 

It's not clear at all. What's the problem ?
 
fx1.net:

Hi, very strange behaviour is found:

I hope this is clear and helps to sort out the issue.

All results should be 0.0006 but as soon i pass the string to a function it seems to have serious bug. This might cost us big trouble! Build 670. Same behavious on 646 too. 


DoubleToString is intended to be used in the more recent versions of mql4 as it brings it closer to mql5 language coding.

DoubleToStr is the old mql4 style. Not a problem but you should be aware of it.


However... there isn't any problem with your example though.

0.0006 and 0.00060 are mathematically equal values.

The reason you are seeing different numbers in your journal output is because you are formatting as such.

   Print("LocalLots * RemoteLots = ",LocalLots*RemoteLots);    // returns 0.0006
   Print("LocalLots * RemoteLots = "+DoubleToStr(LocalLots*RemoteLots,5));    // prints  0.0006

The first line will output 0.0006 and the second line will output 0.00060 .

It's doing exactly what you told it to do.

This isn't a bug.

It's an output formatting issue in your code.

- david-forex

 
My bad, tx for reply. i had "-" in output, this confused me! 
Reason: