Operador Mod

L'operador MOD rep dues expressions numèriques i retorna el residu de la divisió.

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 s'arrodoneix a 16.

  2. El valor 5,9 s'arrodoneix a 6.

  3. L'operació 16 MOD 6 retorna 4, el residu de la divisió de 16 per 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.


Sintaxi:


Resultat = Expressió1 MOD Expressió2

Valor de retorn:

Enter

Paràmetres:

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.

Exemple:


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

Ens cal la vostra ajuda!