# Thread: modulo(%) operation with double

1. ## modulo(%) operation with double

I would like to do an operation like:

double a, b, c;

a = (b % c);

But Gcc doesn't allow me to do it, because it says % operation can't be used with double. (Invalid operands to binary %).

How can I do the modulo operation without using % or using the % and double types.

Thanks,

Joćo Pedro

2. With modf() from math.h of course.
modf - C++ Reference

3. The reason for this is that there is no remainder when performing division with a type capable of representing the actual answer.
E.g.
11 / 4 => 2, remainder 3 (where 3 = 11 % 4)
but 11.0 / 4.0 = 2.75, no remainder ever!

4. The reason for this is that there is no remainder when performing division with a type capable of representing the actual answer.
E.g.
11 / 4 => 2, remainder 3 (where 3 = 11 % 4)
but 11.0 / 4.0 = 2.75, no remainder ever!

You can use % with C# or Java with real values...

5. Why doesn't C just do an automatic conversion from double to int in this case?

6. because you would lose your decimal values