Strange behaviour of the NormalizeDouble() function.

 

Hi

I use some notification alerts in my EA for displaying variables. See the picture.

To minimize the number of decimal numbers I use the NormalizeDouble() function to decrease the number of decimals to 2. 

NormalizeDouble(dPosition_Trend_RendementRatio,2)


But sometimes. This function does not work. (see the picture)

Does anybody know why? And how to solve this.


Thanks

Files:
Log.jpg  853 kb
 

Try to look for the variable/fromula for dPosition_Trend_RendementRatio ... Do a special case if there is a zero division or so ...

In general, I mean, you have to consider every case that could happen to get the dPosition_Trend_RendementRatio value.

Also, in printing/showing dPosition_Trend_RendementRatio on chart, you have to change the value to string.

This could help.

Good luck. 

 
snelle_moda:

Hi

I use some notification alerts in my EA for displaying variables. See the picture.

To minimize the number of decimal numbers I use the NormalizeDouble() function to decrease the number of decimals to 2. 

NormalizeDouble(dPosition_Trend_RendementRatio,2)


But sometimes. This function does not work. (see the picture)

Does anybody know why? And how to solve this.


Thanks

This is the nature of the doubles ( https://en.wikipedia.org/wiki/Double-precision_floating-point_format ). E.g. they never will be exactly 3! NormalizeDouble() is only the nearest value to the wanted precision!
Double-precision floating-point format - Wikipedia, the free encyclopedia
Double-precision floating-point format - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Double-precision floating-point format is a computer number format which occupies 8 bytes (64 bits) in computer memory and represents a wide, dynamic range of values by using a floating point. Computers with 32-bit storage locations use two memory locations to store a 64-bit double-precision number; each storage location holds a...
 

Thanks for all the input.


It's not a zero division problem, it's already checked in the code.

Maybe I should use the DoubleToString() function because I only need to see two decimal numbers, is this correct? 

I realize that the NormalizeDouble() function does not round and "CUT" the value off as I was expecting.


Thanks for the help. 

 

Or I need to use both functions Like:

DoubleToString(NormalizeDouble(dPosition_Trend_RendementRatio,2), 2);

Reason: