In C++, floor(9099.96 *100.0) is giving me the answer as 909995. I am expecting 909996.
I am not able to think of explanations here. Any help will be appreciated.Thanks.
In C++, floor(9099.96 *100.0) is giving me the answer as 909995. I am expecting 909996.
I am not able to think of explanations here. Any help will be appreciated.Thanks.
This is the proper result: according to IEEE754 calculator, the value of 9099.96 is represented as 9099.9599609375 in double. After multiplication by 100 you get 909995.99609375. Taking floor gives you 909995.
Try ceil. It will always round the the next greatest number, which in this case will give you 909996. You may also want to look at the round function.