Trimming decimals

Para añadir comentario, por favor Autorícese o regístrese
Jose Antonio
33
Jose Antonio  

I have a sligh issue with decimals.

Let's say I have the following value 1.13820999999. I just need to be 1.13820, that's said, i want to work with 5 decimals only.

The problem I'm facing at it's that when printing the output in console, it shows correctly, but when I use such Normalizated double with 5 decimals, really operate with all of them.


double a = 1.13820999999;
double vn = NormalizeTickValue(a);
Print("Normalized value: ", vn);
Print("Substracting: ", vn-1.1380);
Print("Normal Substract: ", (a-1.1380));

The function which Normalize:

double NormalizeTickValue( double value ) {
   int valorInt = NormalizeDouble(value*100000, 0);
   string valor = IntegerToString(valorInt);
   Print("The string: ", valor);
   return ((double)StringToInteger(valor))/100000;
}

Well, the output is:

2019.03.14 14:39:05.371 mava (EURUSD,M5)        The string: 113821
2019.03.14 14:39:05.371 mava (EURUSD,M5)        Normalized value: 1.13821
2019.03.14 14:39:05.371 mava (EURUSD,M5)        Substracting: 0.0002100000000000435
2019.03.14 14:39:05.371 mava (EURUSD,M5)        Normal Substract: 0.0002099999900000427

What's happening here?

Is there any other way I can accomplish what I need?

Para añadir comentario, por favor Autorícese o regístrese