Download MetaTrader 5

Write to csv rounding issue

To add comments, please log in or register
Make profit on MQL5 services. It's easy!
Baldus 2015.05.26 17:38 

Hi all,

I have come across an issue I don't seem to be able to resolve. When writing data (iOpen, iClose etc..) to a csv file, not all but certainly a lot of entries have an extra of 10 decimals on top of the 5 decimals I normally would like to use.

Examples: 9.105409999999999  or 9.106960000000001

I have tried rounding the numbers with: NormalizeDouble, MathRound (first multiplied and then divided back), converting to string to the 5th decimal, substracting strings to the 5th decimal etc but none of them work.

How come this happens? Why is not all data like this, and more importantly, how to get around this and write with only 5 decimals?

It would be much appreciated of someone could help me with this. Thanks!

Alain Verleyen
Alain Verleyen 2015.05.28 21:46  
Demos Stogios
Demos Stogios 2015.05.29 14:55  


I only would like to make a  remark about Normalisation; well, it will not truncate the floating number in question; it will rather get rid of outstanding 0s, as you can read here 

That is why you r 1.45670000001 will always be like that when you apply NormalizeDouble in it. My advise, unless you use iClose and similars because of accessing history is to use plain Close from the predefined variables, or do a cast to float (float)iClose, besides using the built in Double to string

To add comments, please log in or register