PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I was told it is because (0.1 + 0.7) * 10) is being stored as 7.99999999, and everything after the decimal is cut off by the conversion to int, but why is it being stored as that? Surely ((0.1 + 0.7) * 10) should be being stored as 8 even before the data type conversion?
I was told it is because (0.1 + 0.7) * 10) is being stored as 7.99999999, and everything after the decimal is cut off by the conversion to int, but why is it being stored as that? Surely ((0.1 + 0.7) * 10) should be being stored as 8 even before the data type conversion?
Nope, the values 0.1 and 0.7 are floating point values, and the result of the sum (0. is a floating point value. When you multiply that by 10, despite 10 being an integer, the result is also still a floating point value until it is cast to integer.