I tried to experiment by doing the following, which truncates the quotient before continuing with the operation:

Code:

int main()
{
double num = 10.3;
double den = 3.3;
double mod;
int trun;
trun = num/den;
mod = num - trun*den;
}

The mod becomes 0.40000000000000213. Is this math even correct?

For some reason, my variables are showing up in my Visual Studio Autos window like this:

num 10.300000000000001

den 3.2999999999999998

I'm not sure why.

------------------------------------------------------------------------------

Using the same variable values, but instead using the fmod function for the calculation gives me a slightly different result, which is the following code block:

Code:

#include <math.h>
int main()
{
double num = 10.3;
double den = 3.3;
double mod;
mod = fmod(num,den);
}

The mod result here is 0.40000000000000124, which is slightly different.

I understand the basics of dividing decimals, but I dont know how to get the remainder on paper, so I don't understand how the mod becomes .4 to begin with.

If someone wants to explain to me how to find the remainder of an operation where decimals are divided, I won't mind.

I really want to understand how the fmod function works, though.