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 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 anyway I can get rid of this problem?
calculateAvailableUnits function does some calculation which involves fractions, so the result 29.9999 instead of 30.