# Mod

### From Xojo Documentation

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

## Description

Returns the remainder of the division of two numbers.

## Syntax

result= number1 Mod number2

Part Type Description
result Integer The remainder (as an Integer) of number1 divided by number2.
number1 Number Any number.
number2 Number Any number.

The Mod operator divides number1 by number2 and returns the remainder as result. If either number1 or number2 are non-integers, they are first coerced to Int32s. If number2 is zero, the result is undefined even if number1 is also zero. The only expected behavior is that the application will not crash. To ensure proper program execution, you should test to ensure that number2 is not zero before using Mod.

When converting a floating-point number to an integer, there is always the chance of data loss. The same is true when a floating point value holds a sentinel such as infinity or NaN. Integers do not reserve space for sentinel values, so that information is lost. Converting a floating-point number that represents a sentinel to an Integer yields undefined results.

The Mod operator operates on integers even if it is passed real numbers. For example:

 Dim r as Integer r=5 Mod 2 //returns 1 r=5 Mod 1.99999 //returns 0

If number1 is negative, then result is negative. For example:

 Dim r As Integer r=-10 Mod 3 //Returns -1 r=-10 Mod -3 //Returns -1 r=10 Mod 3 //Returns 1

## Examples

These examples use the Mod operator to divide two numbers and return the remainder.

 Dim r As Integer r=10 Mod 3 //Returns 1 r=2 Mod 4 //Returns 2 r=9.3 Mod 2.75 //Returns 1 r=4.5 Mod 1 //Returns 0 r=25 Mod 5 //Returns 0