Download MetaTrader 5

MathFloor() Issue

To add comments, please log in or register
vivs
48
vivs  

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

Print(MathFloor(11219.0)) gets displayed as 11219.0

but

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

Any idea, why? 

whroeder1
14779
whroeder1  

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
48
vivs  
Thanks for clarification
To add comments, please log in or register