|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
/ Operator (Visual Basic)
Divides two numbers and returns a floating-point result.
The result is the full quotient of expression1 divided by expression2, including any remainder.
The \ Operator (Visual Basic) returns the integer quotient, which drops the remainder.
The data type of the result depends on the types of the operands. The following table shows how the data type of the result is determined.
Operand data types
Result data type
Both expressions are of the Decimal data type
Both expressions are of the Single Data Type (Visual Basic)
Before division is performed, any integral numeric expressions are widened to Double. If you assign the result to an integral data type, Visual Basic attempts to convert the result from Double to that type. This can throw an exception if the result does not fit in that type. In particular, see "Attempted Division by Zero" on this Help page.
If expression1 or expression2 evaluates to Nothing, it is treated as zero.
Attempted Division by Zero
If expression2 evaluates to zero, the / operator behaves differently for different operand data types. The following table shows the possible behaviors.
Operand data types
Behavior if expression2 is zero
Floating-point (Single or Double)
Integral (signed or unsigned)
The / operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.
This example uses the / operator to perform floating-point division. The result is the quotient of the two operands.
The expressions in the preceding example return values of 2.5 and 3.333333. Note that the result is always floating-point (Double), even though both operands are integer constants.