You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
so you couldn't solve this with google and all leads you got?
have you tried hard enough?
output:
Ok, I know why it is happening, but I'm asking - do You know how to make it work?
It does work.
To be honest, I don't totally understand it, but I accept that this is the way it has to be.
We calculate a value and see it as 0.00064, but the program calculates a slightly different value at times because of the way that it works with doubles.
All we need to know is that once a value has been calculated and normalized it will be accepted
and never check for equality, but check for a difference of less than Point
I think that I didn't explain exactly what I'm doing and why... I wanted to test a strategy, where difference between 2 BIDs I will use for stop loss. So stop loss has to be in format double with 5 digits.
Really thanks for Your job, but:
All was working fine until when
because c = a - b is not equal to 0.00064 but... And here I could repeat the whole post.
I will only write this:
Can anyone divide:
double x = 64.0/100000; // x = 0.0006400000000000001
call function whatever... or use command whatever, or do whatever to...
Print (x); where in output x would be = 0.00064 but in DOUBLE format, not string...?
Have you read the mt4 reference of mt4 acc. to NormalizeDouble()?
You might have detected the example there:
NormalizeDouble() seems to be just the wrong functions fro you! I would suggest you to use MathRound instead like
(I know it looks a bit like what we say in German: From the back through the breast into your eye.)
so you couldn't solve this with google and all leads you got?
have you tried hard enough?
output:
I think the OP was asking how to end up with excatly 0.00064 without converting to string and back.
The cause of the error is difficult to understand it has something to do with the way 0.1 does not do right in binary. I think it is similar to the way one third does not do right in decimal it has to be rounded off.
graziani:
This happens because of the floating-point format.
0.0006400000000000001
This is the only way you can store 0.00064 in double or float type of variable.
In your case, you had an error because you tried to use the value without normalizing.
Proper way:
It seems kinda funny that in the 21century we are all using computers that can't do a simple floating point calculation accurately in decimal.
What you can do to avoid error accumulation is cast them to integer then back to double at the end. You can see from the accuracy test that way creates no actual error.
Plus what SDC has written... (I'm putting it here with small change, so maybe someone who will have similar problem could find it)
Now I get it all - I was so sure, that everything I made is as it should be (I checked it 20, 30 times...), but I missed that one of my call function didn't have NormalizeDouble ().
All what I saw was:
And I thought that it is the reason why my program doesn't work as it should.
Guys - thanks for Your time, without You I wouldn't find it at all!! :D
I never realized it was this bad to do floating point calculations ...