Operator
Integer Division
Description
The operator is used to perform Integer division between two numbers.
Usage
result = expression1 \ expression2
Part |
Type |
Description |
---|---|---|
result |
The Integer division of expression1 and expression2. |
|
expression1 |
Number |
Any numeric expression. |
expression2 |
Number |
Any numeric expression. |
Notes
Use this operator when you require division that does not consider the decimal portion of the expressions. The result may differ from systems that round the expressions prior to the division.
If expression1 and expression2 are not integers, they are coerced to Int32. If you divide by zero, the result is undefined even if the numerator is also zero. The only expected behavior is the application will not crash. For that reason, you should always check to see whether the denominator is zero before using .
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.
Use the / operator for floating point division and the Mod operator to obtain the remainder of the division.
You can use Operator IntegerDivide to define the operator for classes.
Sample code
This code stores the result of a division of two numbers in a variable:
Var x As Integer
x = 50.56 \ 30.34 ' x is 1
x = 49.56 \ 25.34 ' x is 1
Compatibility
All project types on all supported operating systems.
See also
/, Mod operators; Operator IntegerDivide function; Operator precedence