Download MetaTrader 5

Why error "possible loss due to conversion", and how to solve this?

To add comments, please log in or register
stargazer
153
stargazer  

I have written this small function which helps any programs to do the normalize of prices (without having to re-type the long normalize command), but it keeps giving this error. How can i solve this?

//+------------------------------------------------------------------+
double normMe(string ins, double price){        
//+------------------------------------------------------------------+
        double dig=SymbolInfoInteger(ins,SYMBOL_DIGITS);
        
        return(NormalizeDouble(price,dig));
}

the error is: possible loss of data due to type conversion    tstEA.mq5    78    12

if theres any suggestion or work around to this? Thx!


Update: Now I do this (as below), and the error disappears!!. but is my solution below ok? Will it have any effects later, is what i am worried....

//+------------------------------------------------------------------+
double normMe(string ins, double price){        
//+------------------------------------------------------------------+
        int dig=(int)SymbolInfoInteger(ins,SYMBOL_DIGITS);
        
        return(NormalizeDouble(price,dig));
}
Alexey Da
Moderator
6678
Alexey Da  

It isn't an error. It's just a warning.

I think this topic helps you

double normMe(string ins,double price)
  {
   int dig=(int)SymbolInfoInteger(ins,SYMBOL_DIGITS);
   return(NormalizeDouble(price,dig));
  }

 

stargazer
153
stargazer  
alexvd:

It isn't an error. It's just a warning.

I think this topic helps you

 

Yes, i read 70-80% before, thats how I know to do that thing (int)...

int dig=(int)SymbolInfoInteger(ins,SYMBOL_DIGITS);

Thanks for letting me know its not error. Its a huge relief to me. This topic is solved, thanks to your reply.

Chris.h
51
Chris.h  

Very old topic but still some questions.


I type :

a)

int sum;
sum = (int) iVolume(NULL,0,0);

With (int) I prevent the "possible loss of data due to type conversion". The data type of iVolume is long and therefore takes 8 byte. Does this operation cause it to take only 4 bytes? Or does this additional code (int) increase the memory size. In other words which of these has the best performance: a) or b)?

b)

int sum;
sum = iVolume(NULL,0,0);
honest_knave
Moderator
2342
honest_knave  

There is no difference between a) and b) except for the compiler warning.

'sum' remains an int; it can't change.

The compiler is warning you that the long value from iVolume will be put into an int, as there is no other choice. It warns you because you haven't explicitly asked for this to happen (but it is going to happen nevertheless).

By typecasting, you are instructing it to put the long value into an int. As you have done this explicitly, there is no need for the warning.

HTH

To add comments, please log in or register