Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Operators

The div / mod Operators (integer division and remainder)

Scroll Prev Up Next More

The div operator takes 2 integer expressions and returns an integer value which is the integer division of the first expression by the second.

 

The mod operator returns the remainder left over from the integer division.

 

The use of the div and mod operators actually mirrors everyday experience, for example when purchasing products or services. Suppose you had $25 and wanted to go to a movie whose entrance price was $10. You would not get 2.5 tickets, you would only get 2 tickets and have $5 remaining.

 

Using the div and mod operators you would express the above as :

nNumTickets = 25 div 10 // equals 2 tickets
nPocketChange = 25 mod 10 // equals $5 left over

Note that using a value of 0 (zero) on the right side of either of these operators will generate a run-time error message.

 


Topic 122300, last updated on 18-Apr-2020