Method: BigDecimal#mult

Defined in:
bigdecimal.c

#mult(other, ndigits) ⇒ Object

Returns the BigDecimal product of self and value with a precision of ndigits decimal digits.

When ndigits is less than the number of significant digits in the sum, the sum is rounded to that number of digits, according to the current rounding mode; see BigDecimal.mode.

Examples:

# Set the rounding mode.
BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up)
b = BigDecimal('555555.555')
b.mult(3, 0)              # => 0.1666666665e7
b.mult(3, 3)              # => 0.167e7
b.mult(3, 6)              # => 0.166667e7
b.mult(3, 15)             # => 0.1666666665e7
b.mult(3.0, 0)            # => 0.1666666665e7
b.mult(Rational(3, 1), 0) # => 0.1666666665e7
b.mult(Complex(3, 0), 0)  # => (0.1666666665e7+0.0i)


2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
# File 'bigdecimal.c', line 2363

static VALUE
BigDecimal_mult2(VALUE self, VALUE b, VALUE n)
{
    ENTER(2);
    Real *cv;
    SIGNED_VALUE mx = check_int_precision(n);
    if (mx == 0) return BigDecimal_mult(self, b);
    else {
	size_t pl = VpSetPrecLimit(0);
	VALUE   c = BigDecimal_mult(self, b);
	VpSetPrecLimit(pl);
	GUARD_OBJ(cv, GetVpValue(c, 1));
	VpLeftRound(cv, VpGetRoundMode(), mx);
        return VpCheckGetValue(cv);
    }
}