divide method

Decimal divide(
  1. Decimal other, {
  2. required int scale,
  3. DecimalRounding rounding = DecimalRounding.exact,
})

Divides to scale fractional digits (negative scales round integer digits). The default rejects a result requiring rounding, including repeating ratios.

Implementation

Decimal divide(
  Decimal other, {
  required int scale,
  DecimalRounding rounding = DecimalRounding.exact,
}) {
  validateScale(scale);
  if (other.coefficient == BigInt.zero) {
    throw UnsupportedError('Division by zero');
  }
  final shift = other.scale - this.scale + scale;
  return _quotient(
    coefficient * (shift > 0 ? _power(shift) : BigInt.one),
    other.coefficient * (shift < 0 ? _power(-shift) : BigInt.one),
    scale,
    rounding,
  );
}