Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

understanding MOD function

Status
Not open for further replies.

SidCharming

Technical User
Jun 18, 2003
73
0
0
US
I can't grasp the concept of using the 'MOD' function. I look at the examples given in the help area and try with my calculator and it just does not make sense.

Example

10 Mod 5 returns 0, but calculator = 0.5
10 Mod 3 returns 1, but calculator = 0.3

can someone assist with understanding this function.

Thanks



Sid from Minnesota
 
Sid from Minnesota

A MOD function returns a WHOLE NUMBER that is a REMAINDER of division

10 MOD 5 SHOULD return ZERO
10 MOD 3 SHOULD return ONE

Check you CALCULATOR!

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
BTW,

My MS Calculator works JUST FINE!

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
The MOD function returns the remainder portion of a division operation.

10 Mod 5 returns 0 because 10/5 = 2 with a remainder of 0.
10 Mod 3 returns 1 because 10/3 = 3 with a remainder of 1

Your calculator may be converting the remainder the corresponding decimal value, which is to divide the remainder by the divisor. In the case of 10 Mod 3, that would be 1/3, with 1 being the remainder, and 3 being the divisor. Hence the 0.333333

As far as 10 Mod 5 returning 0.5 - I don't have a clue.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Sounds like you're doing division and NOT mod

5/10 = .5
3/10 = .3

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
So by my atking 10 divided by 3 with my calculator it returns the value 3.333 should not be regarded. What gives me the remainder other than writing the division long hand method?



Sid from Minnesota
 
So what is the point of using Mod? Seems like a number that is not returned by a standard calculator. What purpose would it have?

Sorry for being ignorant, but I don't quite get it's major function or use.



Sid from Minnesota
 
In that case the remainder is the product of the fractional part and the divisor...
[tt]
.333 * 3 = 1
[/tt]


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
The MOD function gives you the remainder of a division operation. As SkipVought said, the Mod function should return a whole number, and not the fractional decimal part of the result of the division. However, I can see where some calculators would/could show that as a decimal value. But that would not be a calculator that I'd buy.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
If you have to ask, you probably don't need it!

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
For instance, I have a series of numbers that I want to convert to Characters A to Z instead of using digits 0 to 9.

I'd use a combination of the INT function to determine multiples of 26 and the MOD function to determine divisions of 26.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
CajunCenturion,

I am not sure of which calculator you are referring to, but I am using two standard calculators and neither return the whole value of a division... they both return 0.5 or 3.3333.

Maybe I have forgotten a scientific calculator feature... do I need to upgrade to a scientific?



Sid from Minnesota
 
neither return the whole value of a division
Neither does mine DOING DIVISION!

Does you calcualtor use "reverse polish notation" like Hewlett Packard?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I don't think you're executing the Mod function. Perhaps if you describe the keys your press, and the order in which you press them, we can help further.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
So what is the point of using Mod? Seems like a number that is not returned by a standard calculator. What purpose would it have?

An example of using MOD would be to convert Minutes to Days and Hours. You would use the INT function to find the whole number of Days/Hours and the MOD function to return the Number of Minutes left over.

For example, 2000 minutes
To calculate days
Int(2000/1440 [No of Minutes in a day]) = 1
(2000 Mod 1440) = 560 Minutes
To calculate Hours
Int(560/60) = 9 Hours
(560 MOD 60) = 20 Minutes

So 2000 minutes = 1 Day 9 Hours and 20 minutes

If you try to do the same calculation on a standard calculator, 2000/1440 = 1.3888888888, which is not very helpful.

Does that help?

Lightning
 
MOD is good for determining things like page breaks in reports. for example, if you were formatting a report manually and allowed 80 lines per page:
Code:
If (lngLineCounter > 0) Then
  If (lngLineCounter MOD 80 = 0) Then
    'Do page break.
    'Draw Header.
  End If
End If


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
When working with modulo arithmetic on a calculator, multiply the decimal fraction portion of the results by the denominator to get the value of the "remainder".

"(2000/1440 [No of Minutes in a day])" = 1.3888888888 Days

1440 * .3888888888 = 559.999999872 (close enough to call it 560)

"(2000 Mod 1440)" = 560 Minutes

"To calculate Hours
(560/60)" = 9.333333333333 Hours

60 * .333333333333 = 19.999999999 (close enough to call it 20)

"(560 MOD 60) = 20 Minutes"

And put it all together....

"So 2000 minutes = 1 Day 9 Hours and 20 minutes"

It has taken me a long time to "get it", but once I finally grasped the modulo (MOD) concept it has been very useful in bracketing ranges of values, especially time values on reports. i.e. how many calls were taken in 15 min intervals throughout the day.

Hope this helps....

WinN.
 
Another example that I have used MOD for is Order Entry data validation. Our customers order from us by the piece but we require them to buy based on agreed upon box qtys that reflect efficient lot sizes for us.

I have a Crystal Report that is run daily to check for Order Qty's that are not in multiples of our box qty along the lines of:

If order_qty MOD box_qty <> 0 then I know that they are not ordering by box qty's.

MOD is very nice to check for these types of things.

Thanks,
Carl



 
Thank you all for the assistance in this... I am going to look into a reverse polish notation calculator (no saying it will be my primary calculator... seems like a learning curve to get used to that type).

I appreciate the responses on how and when this function is used along with the examples.


Sid from Minnesota
 
Sid,

In Start/All Programs/Accessories - you should have a Calculator.

Display the Scientific Calculator -- View/Scientific

10 [Mod] 3 [Enter]

should display 1

Does your other calculator work this way?



Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top