 # modulo operator %

hy there,  I apologize in advance for the silly question, but

8.66 % 3 should be 2.66

as a matter of fact it is equal to $8.66 - 3 \cdot trunc(\frac{8.66}{3})$ = 2.66

I have checked it also with the remainder function in OpenOffice calc and it gives 2.66

Gauss, instead, gives: 8.66%3 = 0.0000

Am I using it the wrong way?

Is there a way to get the same result as in OpenOffice Calc with % in Gauss ?

0

The modulo operator operates on integers. In your example 8.66 is being rounded to 9 and (9 % 3) = 0 so, that explains what you are seeing. If you want a decimal or floating point modulus operation, use the function fmod.

r = fmod(8.66, 3);
print r;


will return:

2.66 aptech

1,728

0

Thanks a lot, I really appreciate. 0

The modulo operator operates on integers. In your example 8.66 is being rounded to 9 and (9 % 3) = 0 so, that explains what you are seeing. If you want a decimal or floating point modulus operation, use the function fmod.

r = fmod(8.66, 3);
print r;


will return:

2.66 aptech
1,728
0

Thanks a lot, I really appreciate. ### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.