operator % method

FdcDecimal operator %(
  1. Object other
)

Returns the remainder after dividing this decimal by other.

Implementation

FdcDecimal operator %(Object other) {
  final right = _coerceOperand(other, operation: '%');
  if (right.scaledValue == BigInt.zero) {
    throw UnsupportedError('Division by zero');
  }

  final commonScale = scale > right.scale ? scale : right.scale;
  final leftScaled = _rescaleExact(
    scaledValue,
    fromScale: scale,
    toScale: commonScale,
  );
  final rightScaled = _rescaleExact(
    right.scaledValue,
    fromScale: right.scale,
    toScale: commonScale,
  );
  return FdcDecimal.fromScaled(leftScaled % rightScaled, scale: commonScale);
}