Hi, im having trouble understanding why im getting the following return.
In the following code :
number = 9553700000000000
But when i move the 1st digit down to 8 as follows :
number = 8553700000000001
The last digit is 1
It seems whenever number is at 0.9 or above it returns 0 at end but, at or below 0.8 it returns 1 at end?
Very odd theres something i dont understand here.
Can someone please explain
Do a search on the forum. There are many, many threads about this as most coders (especially newbie coders) don't understand that floating-point is represented in binary form which cannot equate to exact decimal values in all cases.
Do do the search and read-up on the information presented.
Floating-point has an infinite number of decimals, it's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia
See also The == operand. - MQL4 programming forum 2013.06.07
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy. question about decima of marketinfo() - MQL4 programming forum 2016.05.18
Thanks I will look into this more
thanks okay i will look into this
This is how floating-point doubles work. All numbers >= 2^53 (9007199254740992) are even integers. Odd numbers greater than 2^53 are rounded to the nearest even.
You can use this link to check it: https://baseconvert.com/ieee-754-floating-point
Please enable the necessary setting in your browser, otherwise you will not be able to log in.