Modulus Calculation of Decimal Numbers [8.75 % .5]

ptaxler

New member
Joined
May 18, 2017
Messages
4
Hi Experts,

I need some help with modulus calculation of decimal numbers. I understand modulus is actually the remainder when we divide two numbers. I can easily calculate modulus for integers but I need some help with decimals.

I don't understand why the result of 8.75 % .5 = .25

According to me 8.75 % .5 should be 0 because .5 divides 8.75 perfectly and we get 17.5 as the quotient and 0 remainder.

17.5 x .5 = 8.75

Can someone please help?
 
Hi Experts,

I need some help with modulus calculation of decimal numbers. I understand modulus is actually the remainder when we divide two numbers. I can easily calculate modulus for integers but I need some help with decimals.

I don't understand why the result of 8.75 % .5 = .25

According to me 8.75 % .5 should be 0 because .5 divides 8.75 perfectly and we get 17.5 as the quotient and 0 remainder.

17.5 x .5 = 8.75

Can someone please help?
In [mod] operations, a proper quotient must be an integer.
 
Another way to think about it is to recall what is means that "x (perfectly/evenly/cleanly) divides y." It means that the result of x / y is an integer. You've correctly done the division and discovered that 8.75 / 0.5 = 17.5, but you've incorrectly interpreted the result. 17.5 is not an integer. 0.5 goes into to 8.75, 17 times, with a little bit left over. This is the (non-zero) remainder.

But how much is this remainder? Well, there's two ways to calculate it. One is to note that 17 * 0.5 = 8.5 and 8.75 - 8.5 = 0.25, therefore the remainder is 0.25. Another way would be to note that the remainder will be half of the divisor, or 0.5 * 0.5 = 0.25.
 
Top