Skip to main content

Decimal.%

%that

Group: Operators
Aliases: modulo, modulus, remainder

Documentation​

Computes the remainder when dividing this by that.

Arguments to % will undergo automatic conversions such that you need not convert other numeric types to Decimal manually.

Arguments​

  • that: The number to divide this by.

Examples​

Computing the remainder when dividing 10 by 3 (which is 1).​

      remainder = Decimal.new 10 % 3
# => 1

Computing the remainder of a negative number.​

      remainder = Decimal.new -5 % 3
# => -2

Remarks​

Negative Arguments​

When the first argument to % is negative, the result will also be negative.