You can calculate modulus more expensively (but easier to understand) 
like this:

def remainder(num, divided_by)
  num - (num / divided_by).floor * divided_by
end

'floor' effectively gets rid of everything past the decimal point and 
returns an integer.

We know intuitively that if we divide 401 by 100, we get 4 remainder 1.

Using the calculation (let's assume for laughs we have floating point 
numbers),

401.0 - (401.0 / 100.0).floor * 100.0 =
401.0 - (4.01).floor * 100.0 =
401.0 - 4 * 100.0 =
401.0 - 400.0 = 1.0

remainder 401, 100 => 1
remainder 40, 100 => 40
remainder 123456, 87 => 3
remainder 123.45, 100.0 => 23.45

These values agree with the results of using '%'.

Hope this helps.

-- 
Posted via http://www.ruby-forum.com/.