I have a questions on the coding to nt_remainder_without_modulo doesn’t use the % operator!
Write a method that returns the decimal remainder of dividing two integers.
HINT: Use dec_remainder_of_two_floats as a helper method,
but don’t forget to pass the proper type of argument
def dec_remainder_of_two_integers(i_dividend, i_divisor)
i_dividend.to_f%i_divisor.to_f/i_divisor
end
Why is the above correct and the below wrong?
def dec_remainder_of_two_integers(i_dividend, i_divisor)
i_dividend%i_divisor/i_divisor.to_f
end
Failures:
-
methods.rb int_remainder_without_modulo doesn’t use the % operator
Failure/Error: (i_dividend%i_divisor)/(i_divisor.to_f)(Double “Integer”).%(2)
expected: 0 times with any arguments
received: 1 time with arguments: (2)./lib/methods.rb:97:in `dec_remainder_of_two_integers’
./lib/methods.rb:109:in `int_remainder_without_modulo’
./spec/methods_spec.rb:144:in `block (3 levels) in <top (required)>’