# Strange behaviour of the NormalizeDouble() function.

Are you a good trader? Become a signals provider and make even more money!
602
2015.10.16 17:49

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
1448
2015.10.16 20:30

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.

6592
2015.10.16 21:25
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
• 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...
602
2015.10.16 22:17

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.

602
2015.10.16 22:20

Or I need to use both functions Like:

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