
Is there a way to use the modulo operation in a macro? I could think about this workaround:
mod10(x) = (x/10 -floor(x/10)) * 10
but that seems really inelegant since computers have the modulo operation built in
Is there a way to use the modulo operation in a macro? I could think about this workaround:
mod10(x) = (x/10 -floor(x/10)) * 10
but that seems really inelegant since computers have the modulo operation built in
roll20 does indeed support modulo arithmetic. The % symbol can be used, as in:
x % 10
will give the mod 10 of x.
From Math Operators and Functions on the wiki:
%
, for modulus division. The result ofa % b
is the remainder ofa / b
. If you think back to when you were first learning long division without getting into decimals, you were learning how to perform modulus division. Modulus is useful, for example, to test whether a value is even or odd:a % 2
will be 0 if a is even (and positive) and 1 if a is odd (and positive). In general, the result ofa % b
when a and b are both whole numbers will be a whole number in the range[0, |b| - 1]
where|b|
is the absolute value of b. (If a is less than 0, the result will be negative, including -0. -0 is functionally equivalent to 0.)