I try to use the ceiling function and get some weird results. If I perform a stream operation on a decimal number times a hundred, I get a certain result. However, if I directly perform ceil on the result of this multiplication, I get a completely different result. Another twist is that these different results occur only for certain numbers. Any help would be appreciated.
#include <stdio.h>
#include <cmath>
int main ()
{
cout << "The ceiling of " << 411 << " is " << ceil(411) << endl;
cout << "The ceiling of 4.11*100 is " << ceil(4.11*100) << endl;
cout << "The ceiling of " << 121 << " is " << ceil(121) << endl;
cout << "The ceiling of 1.21*100 is " << ceil(1.21*100) << endl;;
}
OUTPUT:
The ceiling of 411 is 411
The ceiling of 4.11*100 is 412
The ceiling of 121 is 121
The ceiling of 1.21*100 is 121
source
share