Problem using MOD (and INT) functions with some divisors less than 1
I'm having a problem setting up a formula that will check whether a given dollar value (i.e., a number with exactly two decimal places, like 1.25) is evenly divisible by a nickel (i.e., 0.05).
I thought the MOD function would do the trick, so I tried the following:
IF (MOD(priceA,0.05)=0, calculationX, calculationY)
where "calculationX" should be performed if priceA is evenly divisible by 0.05 (i.e., dividing priceA by 0.05 produces a remainder of 0) and "calculationY" should be performed if not.
However, I found the MOD function produced lots of apparent errors when I entered the multiples of 0.05 between 0.05 and 2.00 for priceA.
The usage notes for MOD tell us that MOD(a,b) is equivalent to a-b*INT(a/b), so I tried using INT instead in my formula. Again, lots of errors (see table below for my particular results with both these functions).
I wonder if anyone can tell me what I'm doing wrong? Am I perhaps misunderstanding how MOD is supposed to work (it's been a long time since I've been in math class)? Could this be a syntax problem? The results that I got didn't seem to be affected by whether I set the cell format for priceA to be "automatic" or "number" or "currency". (I originally used "number", set to two decimal places, but I tried others.) Also, the functions appear to work correctly for the same range of numbers (multiples of 0.05 between 0.05 and 2.00) when I set the divisor to a quarter (0.25). But when I used a dime (0.10) as the divisor, I again got lots of errors.
I was able to come up with a workaround, namely multiplying priceA by 100 and using 5 as the divisor (though even this workaround produced an apparent error for priceA=1.15). But I found nothing in the "Formulas and Functions User Guide" to suggest that using a number that's less than 1 as a divisor might be a problem for MOD or INT; in fact one of the examples for MOD uses 0.75 as the divisor.
My results were obtained with Numbers '09, version 2.1 (436), on a Mac Mini running Mac OS X version 10.6.8.
What I expected was that all the results in the column that used the formula MOD(priceA, 0.05) should be 0 (i.e., no remainder) and all the results in the column that used the formula INT(priceA/0.05) would be the whole numbers from 1 through 40, increasing by 1 with each successive row. Here's what I got:
| priceA | MOD(priceA, 0.05) | INT(priceA/0.05) |
|---|---|---|
| 0.05 | 0.00 | 1.00 |
| 0.10 | 0.00 | 2.00 |
| 0.15 | 0.05 | 2.00 |
| 0.20 | 0.00 | 4.00 |
| 0.25 | 0.05 | 5.00 |
| 0.30 | 0.05 | 5.00 |
| 0.35 | 0.05 | 6.00 |
| 0.40 | 0.00 | 8.00 |
| 0.45 | 0.05 | 9.00 |
| 0.50 | 0.05 | 10.00 |
| 0.55 | 0.00 | 11.00 |
| 0.60 | 0.05 | 11.00 |
| 0.65 | 0.05 | 13.00 |
| 0.70 | 0.05 | 13.00 |
| 0.75 | 0.05 | 15.00 |
| 0.80 | 0.00 | 16.00 |
| 0.85 | 0.05 | 17.00 |
| 0.90 | 0.05 | 18.00 |
| 0.95 | 0.05 | 18.00 |
| 1.00 | 0.05 | 20.00 |
| 1.05 | 0.05 | 21.00 |
| 1.10 | 0.00 | 22.00 |
| 1.15 | 0.05 | 22.00 |
| 1.20 | 0.05 | 23.00 |
| 1.25 | 0.05 | 25.00 |
| 1.30 | 0.05 | 26.00 |
| 1.35 | 0.00 | 27.00 |
| 1.40 | 0.05 | 27.00 |
| 1.45 | 0.05 | 28.00 |
| 1.50 | 0.05 | 30.00 |
| 1.55 | 0.05 | 31.00 |
| 1.60 | 0.00 | 32.00 |
| 1.65 | 0.05 | 32.00 |
| 1.70 | 0.05 | 34.00 |
| 1.75 | 0.05 | 35.00 |
| 1.80 | 0.05 | 36.00 |
| 1.85 | 0.05 | 37.00 |
| 1.90 | 0.05 | 37.00 |
| 1.95 | 0.05 | 39.00 |
| 2.00 | 0.05 | 40.00 |
Mac OS X (10.6.8), Numbers '09, version 2.1 (436)