to do with the way floating points work, try adding 0.1 before rounding
Pretty absurd.
So, you mean it is a bug?
Pretty absurd.
So, you mean it is a bug?
it's a common issue not limited to MQL
you just have to deal with it
William has a whole thing he has posted on floating point numbers here, have a little digit's a common issue not limited to MQL
you just have to deal with it
William has a whole thing he has posted on floating point numbers here, have a little digWhat's the difference between 50*2.55 and 127.5 ?
What's the difference between MathRound(50*2.55) and MathRound(127.5) ?
What's the difference between 50*2.55 and 127.5 ?
What's the difference between MathRound(50*2.55) and MathRound(127.5) ?
like I said just do a little digging if you want the detail, plenty of coverage on the internet and some here.
But 2.55 is not necessarily 2.55 and 50*2.55 is not necessarily 127.5 because the decimal precision is only for your eyes in real terms we are dealing with floating point numbers.... try google
so this simple bit of code
for(int iC=0.0; iC < 20; iC++) { Print(iC*0.1 + " " + MathRound(iC*0.1)); }
produces this output.... see the problem
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.0 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.1 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.2 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.3 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.4 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.5 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.6000000000000001 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.7000000000000001 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.8 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.9 1.0
like I said just do a little digging if you want the detail, plenty of coverage on the internet and some here.
But 2.55 is not necessarily 2.55 and 50*2.55 is not necessarily 127.5 because the decimal precision is only for your eyes in real terms we are dealing with floating point numbers.... try google
so this simple bit of code
produces this output.... see the problem
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.0 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.1 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.2 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.3 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.4 0.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.5 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.6000000000000001 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.7000000000000001 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.8 1.0
2021.01.29 18:26:24.386 Scratch (UsaInd-sb,D1) 0.9 1.0
Strange, thanks. It seems we ALWAYS need to prepare the floating values, no matter how those look like.
- 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 guys,
This code:
Gives this: 127,5 / 127.0 # 128.0
Why not: 127,5 / 128.0 # 128.0?