mibuso.com

Microsoft Business Solutions online community
It is currently Thu Apr 17, 2014 12:14 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: How to use DIV and MOD
PostPosted: Fri Sep 19, 2008 8:42 pm 
Online
MVP Microsoft Dynamics NAV

Joined: Fri Jun 11, 2004 9:05 pm
Posts: 4990
Location: Los Angeles, CA
Country: United States (us)
Sorry guys, I keep having to search to get the results. For some reason DIV and MOD usage are not explained anywhere on the online help. So I just want to put this here so I can book mark to it. And yes, I do use mibuso for some of my code repository.

x := 5 DIV 2
y := 5 MOD 2

RESULT:
x = 2
y = 1

_________________
Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work

Getting Started with Dynamics NAV 2013 Application Development = my book


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:03 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7965
Location: Howell, MI
Country: United States (us)
DIV is integer division. 5 DIV 2 equals 2 because 2 times 2 equals 5 or less.

MOD is Modulus (I think, not quite sure about the word) but gives you the remainder of integer division.

So ((5 DIV 2) * 2) + (5 MOD 2) = 5.

I always have to put it on a test form to figure out which one is which :oops:

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:05 pm 
Offline

Joined: Mon Mar 08, 2004 2:42 pm
Posts: 3255
Location: Hannover
Country: Germany (de)
:-k i doesn't understand the problem (if there is one)

_________________
Do you make it right, it works too!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:31 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12283
Location: Brno
Country: Czech Republic (cz)
garak wrote:
:-k i doesn't understand the problem (if there is one)


No, there is no problem, just lack of documentation. But these functions is common in other languages and it is not problem to find the meaning...

http://en.wikipedia.org/wiki/Modulo_operation

I think that DIV do not need more explanation... ;-)

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:37 pm 
Offline

Joined: Mon Mar 08, 2004 2:42 pm
Posts: 3255
Location: Hannover
Country: Germany (de)
ah, ok ... (never checked if modulo or division is in the online help..)

is this known :?:

Code: Select all
for i := 10 DownTo 1 do begin
end;

_________________
Do you make it right, it works too!


Last edited by garak on Fri Sep 19, 2008 11:25 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 11:12 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Aug 14, 2001 7:01 am
Posts: 5346
Location: Prague
Country: Czech Republic (cz)
My NAV reference guide, is actually a Pascal developers guide.

Great book, an it has all this stuff in it.

_________________
David Singleton
Dynamics NAV Freelancer
Dynamics Book
Go-Live International


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 11:17 pm 
Online
MVP Microsoft Dynamics NAV

Joined: Fri Jun 11, 2004 9:05 pm
Posts: 4990
Location: Los Angeles, CA
Country: United States (us)
Well.. I just put it on here because I get confused which is which as well. So now we all know in a thread with a clear topic.

And knowing is half the battle. :mrgreen:

_________________
Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work

Getting Started with Dynamics NAV 2013 Application Development = my book


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 1:58 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7965
Location: Howell, MI
Country: United States (us)
You should post these in the book wiki, that's a really good place for reference material like this.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: How to use DIV and MOD
PostPosted: Fri Jul 09, 2010 9:18 am 
Offline

Joined: Wed May 05, 2010 12:00 pm
Posts: 103
Country: India (in)
HI ALEX :)

The Integer Divide (DIV) OperatorThe integer divide operator is used only as a binary operator. Its purpose is to
divide the numeric term preceding it by the numeric term following it. The result
type of this division is always of type Integer. If the second term is zero (0), a
run-time error occurs. Any decimals that resulted from an ordinary division are
dropped. Therefore, the result of 17 DIV 8 is 2, whereas the result of 17 DIV 9 is
1.
The Modulus (MOD) OperatorThe modulus operator (or the remainder operator) is used only as a binary
operator. Its purpose is to divide the numeric term preceding it by the numeric
term following it by using the integer division method and then return the
remainder of that division. The result of this operation is always of type Integer.
If the second term is zero (0), a run-time error occurs. The following shows
examples of modulus operator usage.
• 17 MOD 8 = 1
• 17 MOD 9 = 8
The modulus operator requires two numbers. The first number is the one that is
converted by using the modulus function and the second number represents the
number system being used. By definition the number system starts at zero and
ends at the second number minus one. For example, if the second number is ten,
the number system that is used is from zero to nine. Therefore, the modulus
represents what the first number converts to, if the numbering system only had
the number of values indicated by the second number and the first number is
forced to restart from zero.
The following example shows several modulus operations:
• 15 modulus 10 is 5 (because 9 is the last number available, 10 is
represented by going back from the start, or zero, 11 is 1, 12 is 2, and
so on)
• 6 modulus 10 is 6
• 10 modulus 10 is 0
• 127 modulus 10 is 7
The result is the same if the first number is divided by the second by using an
integer only and the remainder is returned as the value.

_________________
smile always
shona
That which you seek inside is that which you find outside


Top
 Profile E-mail  
 
 Post subject: Re: How to use DIV and MOD
PostPosted: Fri Jul 09, 2010 5:26 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 7039
Location: L.I., New York
Country: United States (us)
I use it in a check when we split PO's due to 1/2 30 days 1/2/ 60 days terms.
We used to manually cut the Qty to Invoice in half , which therefor cuts the invoice amount in half.
Then we post with 30 days terms. Then we post the (remaining) other half with 60 days terms.
Giving us two vendor ledger entries with the correct terms. But then we started getting these terms on PO's that had 100 items and manually this was exhausting. So using MOD I can see if the amount is cleanly divisible by 2 & if not it gives us a message to check the Item and handle that manually.

Hail MOD!!
Remainder := Purchline."Quantity Received" MOD 2;
IF Remainder <> 0 THEN MESSAGE('Item %1 Needs Rounding',Purchline."No.");

Code: Select all
OnPush()
IF NOT DIALOG.CONFIRM(Text1,TRUE)
THEN EXIT
ELSE
  Purchline.RESET;
  Purchline.SETRANGE(Purchline."Document Type","Document Type");
  Purchline.SETRANGE(Purchline."Document No.","No.");
  IF Purchline.FIND('-') THEN
    REPEAT
     IF Purchline."Quantity Received" <>0 THEN BEGIN
      Purchline."Qty. to Invoice" := (Purchline."Quantity Received" / 2);
      Remainder := Purchline."Quantity Received" MOD 2;
      IF Remainder <> 0 THEN MESSAGE('Item %1 Needs Rounding',Purchline."No.");
      Purchline.VALIDATE("Qty. to Invoice");
      Purchline.MODIFY;
     END;
    UNTIL Purchline.NEXT = 0;

_________________
Harry Ruiz
http://www.BiloBeauty.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: How to use DIV and MOD
PostPosted: Tue Jun 14, 2011 8:57 am 
Offline

Joined: Tue May 31, 2011 2:33 pm
Posts: 8
Country: Belgium (be)
Hello,

Has anyone tried to use DIV in combination with BigInteger in NAV2009 RTC?
If you execute following code in NAV2009 you'll get following messages:

Code: Select all
LText := FORMAT(DELCHR(PBankAccountNo,'=',DELCHR(PBankAccountNo,'=','0123456789')) + 'BE' + '00');
  FOR i := 1 TO STRLEN(LText) DO BEGIN
    LConvertText := LConvertText + FORMAT(GetRomanNoIBAN(COPYSTR(LText, i, 1)));
  END;
  EVALUATE(LAccountNo, LConvertText);
  LRest := LAccountNo - ((LAccountNo DIV 97) * 97);
  MESSAGE(format(LREST));


Message in Classic Client (which is correct):
---------------------------
Microsoft Dynamics NAV Classic
---------------------------
88
---------------------------
OK
---------------------------

Message in Role Tailored Client (which is incorrect):
Microsoft Dynamics NAV
---------------------------

235002258041864280
---------------------------
OK
---------------------------

Anyone got any ideas?


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: