Download MetaTrader 5

MathFloor() Issue

To add comments, please log in or register
Register as a seller and start offering your signals!
vivs 2015.06.29 08:10 

I am getting a confusing issue with MathFloor() function in mql4.

Print(MathFloor(11219.0)) gets displayed as 11219.0


Print(MathFloor(10000*1.12190)) gets displayed as 11218.0?

Any idea, why? 

whroeder1 2015.06.29 11:45  

Floor returns a double. So Print(MathFloor(11219.0) is the same Print(MathFloor(11219.xxxx) is the same as Print(11219.0000). Print(MathFloor(10000*1.12190)) is the same as Print(MathFloor(11219.xxxxx)) is the same as Print(11219.000).

What you have is a double 11218.999999 which prints as 11219.0. but floor(11218.999999*10000) is floor(11218.9999) which is 11218.0000. 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 The == operand. - MQL4 forum

vivs 2015.06.29 14:05  
Thanks for clarification
To add comments, please log in or register