Share via


Operador \ (Visual Basic)

Divides two numbers and returns an integer result.

expression1 \ expression2

Parts

  • expression1
    Required. Any numeric expression.

  • expression2
    Required. Any numeric expression.

Supported Types

All numeric types, including the unsigned and floating-point types and Decimal.

Result

The result is the integer quotient of expression1 divided by expression2, which discards any remainder and retains only the integer portion. This is known as truncation.

O tipo de dados de resultado é um tipo numérico apropriado para os tipos de dados de expression1 e expression2. See the "Integer Arithmetic" tables in Tipos de dados de resultados de operador (Visual Basic).

The Operador / (Visual Basic) returns the full quotient, which retains the remainder in the fractional portion.

Comentários

Before performing the division, Visual Basic attempts to convert any floating-point numeric expression to Long. If Option Strict is On, a compiler error occurs. If Option Strict is Off, an OverflowException is possible if the value is outside the range of the Tipo de dados Long (Visual Basic). The conversion to Long is also subject to banker's rounding. For more information, see "Fractional Parts" in Funções de conversão de tipo (Visual Basic).

Se expression1 ou expression2 for avaliada como nada, ela é tratada como zero.

Attempted Division by Zero

If expression2 evaluates to zero, the \ operator throws a DivideByZeroException exception. This is true for all numeric data types of the operands.

ObservaçãoObservação

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 Procedimentos de operador (Visual Basic).

Exemplo

The following example uses the \ operator to perform integer division. The result is an integer that represents the integer quotient of the two operands, with the remainder discarded.

Dim resultValue As Integer
resultValue = 11 \ 4
resultValue = 9 \ 3
resultValue = 100 \ 3
resultValue = 67 \ -3

The expressions in the preceding example return values of 2, 3, 33, and -22, respectively.

Consulte também

Referência

Operador \=

Operador / (Visual Basic)

Opção declaração estrito

Operadores Aritméticos (Visual Basic)

Precedência de operadores no Visual Basic

Operadores listados por Funcionalidade (Visual Basic)

Conceitos

Operadores aritméticos em Visual Basic