Operador Mod

El operador MOD recibe dos expresiones numéricas y devuelve el residuo de la división.

For example, the result of 21 MOD 6 is 3 because after dividing 21 by 6, the remainder of the division is 3.

If the MOD operation involves non-integer values, both operands are rounded to the nearest integer values. Hence, the value returned by a MOD operation will always be an integer number.

For example, the expression 16.4 MOD 5.9 is evaluated as follows:

  1. El valor 16,4 se redondea a 16.

  2. El valor 5,9 se redondea a 6.

  3. La operación 16 MOD 6 devuelve 4, el residuo de la división de 16 entre 6.

note

Be aware that BASIC's MOD operator and Calc's MOD Function behave differently. In Calc, both operands can be decimal values and they are not rounded before division, thus the resulting remainder may be a decimal value.


Sintaxis:


Resultado = Expresión1 MOD Expresión2

Valor de retorno:

Entero

Parámetros:

Result: Any numeric variable that contains the result of the MOD operation.

Expression1, Expression2: Any numeric expressions for which you want to calculate the remainder after the division of Expression1 by Expression2.

Ejemplo:


Sub ExampleMod
    Dim a As Double, b as Double
    a = 10 : b = 4
    Print a Mod b 'Returns 2
    a = 18 : b = 3.2
    Print a Mod b 'Returns 0
    a = 16.4 : b = 5.9
    Print a Mod b 'Returns 4
End Sub

¡Necesitamos su ayuda!