Hi everybody this is my first time on the community.
Hope not to bother anybody with silly questions.
I noticed that doing many operations with Double or Float variables returns imprecise results.
I created this simple code as example:
Opening the resulting “File.txt” and scrolling down you will immediately notice numbers that I wouldn’t really expect.If math hasn’t become an opinion yet, the code above shouldn’t give numbers like:
2.100000000000001
6.199999999999986
for the Double variable and:
6.10001
8.75002
for the Float variable.
Notice that both “for” loops are terminated one iteration
earlier because
10.00000000000001 is greater than 10
and also
10.00002 is greater than 10.
Other two things to notice from this code (if I’m not asking too much) is the two annoying warnings from MetaEditor:
y=0.05 ----> Truncation of constant variable.
and
y=y+0.05 ----> Possible loss of data due to type conversion.
It seems that metaeditor is confusing Float type with Integer type.
Thanks a lot in advance for your helpfulness and patience.
hi
you must use NormalizeDouble() function.
there is a good article that covers that topic on mql4 site:
- www.mql5.com
Thank you for the hint Investeo
Could you tell me what's going on here?
double b=8.050000000000001; Alert(NormalizeDouble(b,2));
why the output is still 8.050000000000001 ??
Also does anybody knows why I'm having the following warnings from MetaEditor:
y=0.05 ----> Truncation of constant variable.
and
y=y+0.05 ----> Possible loss of data due to type conversion.
It seems that metaeditor is confusing Float type with Integer type.
- www.mql5.com
https://www.mql5.com/en/docs/basis/types/double
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody this is my first time on the community.
Hope not to bother anybody with silly questions.
I noticed that doing many operations with Double or Float variables returns imprecise results.
I created this simple code as example:
Opening the resulting “File.txt” and scrolling down you will immediately notice numbers that I wouldn’t really expect.If math hasn’t become an opinion yet, the code above shouldn’t give numbers like:
2.100000000000001
6.199999999999986
for the Double variable and:
6.10001
8.75002
for the Float variable.
Notice that both “for” loops are terminated one iteration earlier because
10.00000000000001 is greater than 10
and also
10.00002 is greater than 10.
Other two things to notice from this code (if I’m not asking too much) is the two annoying warnings from MetaEditor:
y=0.05 ----> Truncation of constant variable.
and
y=y+0.05 ----> Possible loss of data due to type conversion.
It seems that metaeditor is confusing Float type with Integer type.
Thanks a lot in advance for your helpfulness and patience.