Floating-point has an infinite number of decimals, it's your not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia, the free encyclopedia
See also The == operand. - MQL4 programming forum
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum 2016.05.18
try this:
double a = 0.1*3.0;
Floating-point has an infinite number of decimals, it's your not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia, the free encyclopedia
See also The == operand. - MQL4 programming forum
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum 2016.05.18
Thanks a lot, looked through all the threads but still a little confused about how to compare double.
Finally i change the code into this and it work
double Lots=0.1; int divide=Lots*100; double a=3.0/divide; if(OrderLots()==a)
Now this can work well.
But another problem about double type value can't be solved whatever i changed the code
double Lots; int m; double q=AccountEquity(); if(q<=500) { Lots=0.1; } else if(q>500) { m=(AccountEquity()-500)/20; double n=m/100; Lots=0.1+n; }
The OrderLots is alway 0.1, never add lots when AccountEquity is bigger than 500, please check where can i change the code. I've used NormalizeDouble but still the same result.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Please help me with this problem, don't know why i can't double a value by this
But if i use this it will work well
Even i change the code to this
it still doesn't work well.
Never have this problem before, don't know why, anyone have the same proble before?
I print the value of "a", it's the same, both of them is 0.3.
But it just doesn't work in this code if i double it by 0.1*3
if(OrderLots()==a)