# Error description: possible loss of data due to type conversion

718

I've got a couple of them where I'm getting this and I'm lost.

1st up:

`int myDigits = MarketInfo( Symbol(), MODE_DIGITS );`

Now, help text has some sample code that leaves me to believe either I'm not reading it right or I'm loosing my mind:

```   double vbid    = MarketInfo("EURUSD",MODE_BID);
double vpoint  = MarketInfo("EURUSD",MODE_POINT);
int    vdigits = MarketInfo("EURUSD",MODE_DIGITS);
```

2nd up:

`int OrdersToPlace = MathFloor( 100.2 / MarketInfo(FinalSymbol, MODE_MAXLOT ) )+1;`

Help text, again not all that helpful:

The text says: "The function returns integer numeric value closest from below."

The sample shows:

```double  MathFloor(
double  val     // number
);
```

Any ideas on any of these?

Moderator
32374
3741

I'm not exactly sure what you question is but that's not gonna stop me from taking a stab at it.... when you declare your OrdersToPlace variable as an integer that means it is a whole number with no decimal point... when you do all that math on it that includes 100.2 and use MarketInfo which is a double not an integer .. your answer will be a double... i.e. have a decimal point in it..... so if it comes up with 3.56 and you are trying to save it as and integer... it's going to return the integer value closest to 3.56... i.e. 4.....
Again.... myDigits uses MarketInfo() so it needs to be a double..
PipPip....Jimdandy

What it amounts to is that you are losing precision..

440

nondisclosure:

Any ideas on any of these?

I guess the logic behind :

```double  MathFloor(
double  val     // number
);
//---
Return Value

A numeric value representing the largest integer that is less than or equal to val.
```

is just that, a double function returns a double numeric value equal to the largest integer.

If your calculations include doubles, even if the result is a whole number, it will be a double type that has a numeric value of an integer type.

Does it make any sense ?

Example : int x =1; double z = 1.0;

Both have a numeric value of 1. So they're equal but not quite. One is of integer type, the other one is a double.

Possible loss of data due to conversion happens when you try things like int y=x+z;

The result is 2, it looks like an int type but it's the sum of a double and an integer.

Some use that to get the int numeric value of a double like this :

double x = 3.5 ; int z = 2;

int y = x-z ; you get y = 1 and a " possible loss of data due to conversion" warning that you will ignore if you did that on purpose.

The rest

```   int    vdigits = MarketInfo("EURUSD",MODE_DIGITS);

For the above 2 lines, as long as MarketInfo remains a double type function,

the error is in the documentation and you deserve 100 credit points for pointing that out

Here, if this is your code (else if it's from documentation, they made another mistake )

`int OrdersToPlace = MathFloor( 100.2 / MarketInfo(FinalSymbol, MODE_MAXLOT ) )+1;`

you try to assign to an integer type the numeric value equal to an integer but the format of a double type variable.

Sort of : int type = double type(double/double)+1; Mix and match.

You don't know how hard it is to try and explain these things ! Does it make any sense ?

It's like a particular case of a double type when the numeric value is equal to an integer, but that doesn't make it less of a double.

A double remains a double type even when the value hold by it is equal to the value of an integer.

OrdersTo Place is of int type. 100.2 is a double. MathFloor is adouble hence it's return has to be a double type. Then you say an int type = double type !

And that's how you get the possible loss of....... warning.

The program doesn't know if you did that on purpose or it's just a mistake so it will warn you but will compile and run it.

If in fact that is your intention, to get the integer numeric value and store it into an int type variable, you tell the program to shut up like this :

`int OrdersToPlace =(int) MathFloor( 100.2 / MarketInfo(FinalSymbol, MODE_MAXLOT ) )+1;`

Now it knows you did it on purpose and you won't get the warning.

Did it help at all ?

Cheers

15554

1. `int OrdersToPlace =(int) MathFloor( 100.2 / MarketInfo(FinalSymbol, MODE_MAXLOT ) )+1;`
OrdersToPlace is wrong. If lots (100.2) exactly match a multiple of maxlot, your number will be one to many. Also some brokers may open partially (see comment)
```   while(lotsNew >= market_minLot){
// If a trade size is bigger than               100.10=33.34+33.34+33.33
// maxlot, it must be split.                     99.99=50.0+49.99
int      nSplit   = MathCeil(lotsNew / market_maxLot);
double   size     = NormalizeLots(lotsNew / nSplit);

int ticket = OrderSend( ...
if(ticket < 0){ ...                                      return(false); }
if( !OrderSelect(ticket,SELECT_BY_TICKET) ){ ...         return(false); }
// out of 15.84) at the price 587.318. Support: Please be advised, during
// periods of high volatility or low liquidity, Limit Orders may be part-
//}ially executed.
} // true```
(from in my code)
2. ```   double vbid    = MarketInfo("EURUSD",MODE_BID);
double vpoint  = MarketInfo("EURUSD",MODE_POINT);
int    vdigits = MarketInfo("EURUSD",MODE_DIGITS);
Don't hard code pairs. That code means you can't use it on another pair or another broker (see comment in OnInitCurrencies() Why don't use just use the predefined variables?
440

WHRoeder:
1. OrdersToPlace is wrong. If lots (100.2) exactly match a multiple of maxlot, your number will be one to many. Also some brokers may open partially (see comment) (from in my code)
2. Don't hard code pairs. That code means you can't use it on another pair or another broker (see comment in OnInitCurrencies() Why don't use just use the predefined variables?

You may have got it wrong here, this

```double vbid    = MarketInfo("EURUSD",MODE_BID);
double vpoint  = MarketInfo("EURUSD",MODE_POINT);
int    vdigits = MarketInfo("EURUSD",MODE_DIGITS);// This looks wrong to me

isn't his code, he was pointing to an error in the documentation.

vdigits is of integer type and MarketInfo is a double type function.

Digits is of int type, MarketInfo("EURUSD",MODE_DIGITS) isn't.

He says he was puzzled when his code

`int myDigits = MarketInfo( Symbol(), MODE_DIGITS );`

done as per documentation example

`int    vdigits = MarketInfo("EURUSD",MODE_DIGITS);`

returned a possible loss of data due to conversion error.

And he is right, the documentation example is wrong.

718

Still not fixed.   And SymbolInfoInteger isn't any help either.  :(
718

Well, for now, I'm going to have to do this (pass symbol to it):

```int GetDigit(string Sym)
{
int ReturnValue=5;
string back=StringSubstr(Sym,3,3);
if(back=="JPY")
{
ReturnValue=3;
}
return(ReturnValue);
}```
Moderator
32374

nondisclosure:
Still not fixed.   And SymbolInfoInteger isn't any help either.  :(

What should fixed ? I can't see any error either in mql4 or in the documentation.

MarketInfo() is a function returning a double type. If used with MODE_DIGITS or MODE_SPREAD, the value returned will an integer.

A double type variable can contain an integer value.

Maybe I missed your point ?

15554

thrdel: returned a possible loss of data due to conversion error. And he is right, the documentation example is wrong.
angevoyageur: A double type variable can contain an integer value. Maybe I missed your point ?
Exactly. MarketInfo(DIGITS) and SPREAD returns an int value as a double. Just suppress the warning when converting the double to int.
`int myDigits = (int) MarketInfo( Symbol(), MODE_DIGITS );`
718

Typecasting.  Grrrrr.

Now I just wish they'd update the help documentation.