in reply to Modulus strangeness (%)

38.91 is a periodic number in binary, so some truncating occurs when the computer tries to store that number as a float. That means that 38.91 * 100 is not equal to 3891.

>perl -le"printf '%.20e', 38.91 3.89099999999999970000e+001 >perl -le"printf '%.20e', 38.91 * 100 3.89099999999999950000e+003

That means you are calculating the modulus of 3890, not 3891.

Solution 1: You could round the number: (1024 is a power of two, so no error is introduced. But 1000 would be fine too since the error introduced by 1000 would be so small that it would be removed by the rounding.)

>perl -le"$n=38.91*100; $n=sprintf('%f',$n*1024)/1024; print $n%5; 1

Solution 2: Work in cents (or even smaller units) instead of dollars, so that your numbers are all integers.

>perl -le"$n=3891; print $n%5; 1

Update: Elaborated a little.