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!
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