I am trying to round a decimal to 2 digits. To do so, I am multiplying my decimal by 100 and using the floor()
function (because I need to round down so that fractions of a penny - I am working with finances - are not counted), then dividing that number by 100.
In the case of the issue, I am doing 86/100
and it is returning 85.99999999999
and I am not sure why.
int main()
{
double balance = 133.45;
double apr = 7.8;
double newBalance = balance * pow((1+((apr/100)/1)), (1));
double interest = newBalance - balance;
double month = interest / 12;
double total = floor(month * 100) / 100;
return 0;
}
I have looked through other sources online, and I haven't been able to find out why.
Is it an edge case with the floor()
function? This is probably a dumb question, but I couldn't find an answer.