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
FYI, I was shocked the first time I have seen that. why the result of 0.1 + 0.2 is not equal to 0.3
I had to study all the floating-point arithmetic (IEEE 754 format) with all of its weirdness, to be able to understand that line of code.
Relevant links:
https://www.wikiwand.com/en/Floating-point_arithmetic
https://floating-point-gui.de/
IEEE 754 Floating Point converter: https://baseconvert.com/ieee-754-floating-point
IEEE Floating-Point Decoder - script: https://www.mql5.com/en/code/19978
Math Utils - library: https://www.mql5.com/en/code/20822
amrali, i made some tests of your example ->
//------------------
double base = 0.1 + 0.2;
double add = 0.3;
double result = base + add;
Comment(result); // 0.03 result for me... it's correct return for me resut // shows me 0.3
// fi I use -> base + add; // shows me -> 0.6000000000000001;
result = NormalDouble(result, 2); // not NormalizeDouble() ... lol
Comment(result);
//-------------------------
If i print 0.1+0.2 ( base), I get right number = 0.3
, but adding base+add ... i get ........ 0.6000000000000000001 again ...
I have made my new "correction function" called-> NormalDouble() and im testing it ... and so far even on result print is shows me -> 0.6 (cool).
I just need to get all thoughts together for posting function in comunity. (let it wouldn't be with possible bugs and other users dont coll me morran again..).
You have gone too far with your childish rants.
Post deleted and
Banned!
You have gone too far with your childish rants.
Post deleted and
Banned!
Had a similar issue. All methods still had some results with rounding errors so I arrived at the following: convert the number to a string and truncate.
Nice, thank
If you want to trucate a double just create an integer variable and set it equal to the double variable. For example, suppose
double Lots =3.245627;
int intlots = Lots; //intlots takes on the value 3
Had a similar issue. All methods still had some results with rounding errors so I arrived at the following: convert the number to a string and truncate.
Hello Rene,
thanks for sharing your code. i tried using it but it seems the function is returning the number of decimal count rather than the truncated value...need some guidance.
here's what i did :
but i'm getting result for BBgap_String to be = 4. what am i doing wrong?
advance thanks !