operator / method
Implementation
Amount operator /(Amount other) {
if (other.value == BigInt.zero) {
throw ArgumentError('Cannot divide by zero.');
}
// 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 division
BigInt resultValue =
(scaledThisValue * BigInt.from(pow(10, maxDecimals))) ~/
scaledOtherValue;
return Amount(
value: resultValue,
decimals: maxDecimals,
);
}