operator + method

Amount operator +(
  1. Amount other
)

Implementation

Amount operator +(Amount other) {
  // Determine the maximum decimals between the two amounts
  int maxDecimals = max(decimals, other.decimals);

  // Scale both amounts to the same decimal level
  BigInt scaledThisValue =
      value * BigInt.from(pow(10, maxDecimals - decimals));
  BigInt scaledOtherValue =
      other.value * BigInt.from(pow(10, maxDecimals - other.decimals));

  // Perform the addition
  BigInt resultValue = scaledThisValue + scaledOtherValue;

  return Amount(
    value: resultValue,
    decimals: maxDecimals,
  );
}