divmod

divmod(p1)
Instance Public methods

Divides by the specified value, and returns the quotient and modulus as BigDecimal numbers. The quotient is rounded towards negative infinity.

For example:

require 'bigdecimal'

a = ::new(â42â) b = ::new(â9â)

q,m = a.divmod(b)

c = q * b + m

a == c -> true

The quotient q is (a/b).floor, and the modulus is the amount that must be added to q * b to get a.

doc_ruby_on_rails
2015-03-31 07:09:12
Comments
Leave a Comment

Please login to continue.