divide method

Decimal divide(
  1. Decimal other, {
  2. int? scale,
  3. RoundingMode? mode,
})

Implementation

Decimal divide(Decimal other, {int? scale, RoundingMode? mode}) {
  if (other == Decimal.zero) {
    throw ArgumentError('Divided by zero');
  }

  final thisRational = this.toRational();
  final otherRational = other.toRational();

  var res = thisRational / otherRational;
  return scale != null && mode != null ? res.withScale(scale, mode) : res;
}