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

 

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));
}
 

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));
  }

 

 
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.

 

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);
 

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

 
Chris.h:

Very old topic but still some questions.


I type :

a)

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)

Thank you very much.

 

How to fix this?


   ObjectSetString (0, "SPREAD", OBJPROP_TEXT, IntegerToString(MarketInfo(NULL, MODE_SPREAD)));

MODE_SPREAD is in int.

OBJPROP_TEXT must be string.

Why IntegerToString doesnt work smoothly ?

 
Ricardo Gunawan:

How to fix this?


MODE_SPREAD is in int.

OBJPROP_TEXT must be string.

Why IntegerToString doesnt work smoothly ?

Try DoubleToString. MarketInfo returns a double.

 
Keith Watford:

Try DoubleToString. MarketInfo returns a double.

Greattt.... You're the best.... Thanks
 
   CopyBuffer(AlligatorDefinition,0,0,3,JawArray);
   CopyBuffer(AlligatorDefinition,1,0,3,TeethArray);

   CopyBuffer(AlligatorDefinition,2,0,3,LipsArray);

possible loss of data due to type conversion

 
Juan Mateo #:
   CopyBuffer(AlligatorDefinition,0,0,3,JawArray);
   CopyBuffer(AlligatorDefinition,1,0,3,TeethArray);

   CopyBuffer(AlligatorDefinition,2,0,3,LipsArray);

possible loss of data due to type conversion

This the MQL4 section. Your post is for MQL5 code. Please post in the correct section and explain in detail if you need help.