Download MetaTrader 5

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

To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
stargazer
152
stargazer 2011.10.26 10:42 

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
6604
Alexey Da 2011.10.26 10:52  

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
152
stargazer 2011.10.26 11:25  
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
52
Chris.h 2017.03.23 10:18  

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
2210
honest_knave 2017.03.23 10:31  

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