Hi all,
Here is a short summary of my piece of code.
double availableUnits = calculateAvailableUnits(some arguments);
int minimumRequiredUnits = getMinimumRequiredUnits(some arguments);
std::cout<<"minimumRequiredUnits = "<<minimumRequiredUnits<<std::endl; //prints 30
std::cout<<"availableUnits = "<<availableUnits<<std::endl; //prints 30
if (availableUnits < minimumRequiredUnits)
{
//throw exception;
}
//rest of the code
Even though both variables have the value 30 in it, the if-condition gets satisfied and exception is thrown, which is wrong. I studied the problem a little more and found that the double variable availableUnits infact doesn't contain 30, instead it contains 29.9999. Is there any way I can get rid of this problem? Also, I cannot use ceil() as this would affect the functionality.
calculateAvailableUnits() function does some calculation which involves fractions, so the result 29.9999 instead of 30.