By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,027 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,027 IT Pros & Developers. It's quick & easy.

MOD function

P: n/a
Appreciate any feedback on the MOD function. I am at a loss to
understand its "mathmatics".

From the help

Result = Number1 MOD Number2 where the result should be the remainder
of the division.

Create a quick form with 3 unbound fields where the values are all
stored as either double or long (doesnt seem to make any difference in
this case) a quick bit of code and we can play and see the results.

Ok lets try 19 Mod 6.7 in normal "maths" we end up with 2.835
(19/6.7)=2.835, we would expect to see the remainder as .8 however we
end up with .5

With 103 / 16 we would expect to see 6.437 (a remainder of .4),
however with the MOD function we get 7.

Obviously I'm missing something here,

TIA


Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Rog
The remainder is not the same as the decimals. In your last example
103 / 16 = 6 plus some decimals. 16 x 6 = 96. The difference between
103 and 96 is 7, which is the result of the mod function.

Nov 13 '05 #2

P: n/a
MOD uses integer math.
Your divisor is rounded before the MOD operation.

In your example of 19 MOD 6.7, the 6.7 is rounded to 7.
The result of 19 MOD 7 is 5.
Hence 19 MOD 6.7 = 5, since 7*2 yields 14, and the remainder is 5.

In your second example:
103 \ 16 = 6
103 MOD 16 = 7
Check:
(16 * 6) + 7 = 103

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mike Reid" <ad******@tpg.com.au> wrote in message
news:9a********************************@4ax.com...
Appreciate any feedback on the MOD function. I am at a loss to
understand its "mathmatics".

From the help

Result = Number1 MOD Number2 where the result should be the remainder
of the division.

Create a quick form with 3 unbound fields where the values are all
stored as either double or long (doesnt seem to make any difference in
this case) a quick bit of code and we can play and see the results.

Ok lets try 19 Mod 6.7 in normal "maths" we end up with 2.835
(19/6.7)=2.835, we would expect to see the remainder as .8 however we
end up with .5

With 103 / 16 we would expect to see 6.437 (a remainder of .4),
however with the MOD function we get 7.

Obviously I'm missing something here

Nov 13 '05 #3

P: n/a
Mike Reid <ad******@tpg.com.au> wrote in message news:<9a********************************@4ax.com>. ..
Appreciate any feedback on the MOD function. I am at a loss to
understand its "mathmatics".

From the help

Result = Number1 MOD Number2 where the result should be the remainder
of the division.
Snip 8<-----
Ok lets try 19 Mod 6.7 in normal "maths" we end up with 2.835
(19/6.7)=2.835, we would expect to see the remainder as .8 however we
end up with .5

With 103 / 16 we would expect to see 6.437 (a remainder of .4),
however with the MOD function we get 7.

Obviously I'm missing something here,

TIA

Mod is an all integer function. 16 x 6 = 96, 103 - 96 = 7.
Nov 13 '05 #4

P: n/a
Well, I learned something new here. I never knew you could
use the MOD function with non-integers!

OK, to answer your question. I believe you are confusing
Mod with the fractional value. In your first case:

1. 19 Mod 6.7
19 / 6.7 = 2.8358208955223880597014925373134. Since
the integer portion is 2
19 Mod 6.7 = 19 - (6.7 * 2) = 5.6

2. 103 Mod 16
103 / 16 = 6.4375. The integer portion is 6
103 Mod 16 = 103 - (16 * 6) = 7

Kevin
Mike Reid<ad******@tpg.com.au> 4/13/2005 12:58:59 AM
Appreciate any feedback on the MOD function. I am at a

lossto
understand its "mathmatics".

From the help

Result = Number1 MOD Number2 where the result should be
the remainder
of the division.

Create a quick form with 3 unbound fields where the values
are all
stored as either double or long (doesnt seem to make any
difference in
this case) a quick bit of code and we can play and see the
results.

Ok lets try 19 Mod 6.7 in normal "maths" we end up with
2.835
(19/6.7)=2.835, we would expect to see the remainder as .8
however we
end up with .5

With 103 / 16 we would expect to see 6.437 (a remainder of.4),
however with the MOD function we get 7.

Obviously I'm missing something here,

TIA

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.