End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
BigDecimal#div
div(value) → integer
div(value, digits) → bigdecimal or integer
ext/bigdecimal/bigdecimal.c
View on GitHub ↗
static VALUE
BigDecimal_div3(int argc, VALUE *argv, VALUE self)
{
VALUE b,n;
rb_scan_args(argc, argv, "11", &b, &n);
return BigDecimal_div2(self, b, n);
}
Divide by the specified value.
- digits
-
If specified and less than the number of significant digits of the result, the result is rounded to that number of digits, according to
BigDecimal.mode.If digits is 0, the result is the same as for the / operator or
quo.If digits is not specified, the result is an integer, by analogy with
Float#div; see alsoBigDecimal#divmod.
See BigDecimal#/. See BigDecimal#quo.
Examples:
Example
a = BigDecimal("4") b = BigDecimal("3") a.div(b, 3) # => 0.133e1 a.div(b, 0) # => 0.1333333333333333333e1 a / b # => 0.1333333333333333333e1 a.quo(b) # => 0.1333333333333333333e1 a.div(b) # => 1