applyRate method

Money applyRate(
  1. Money amount
)

Apply the exchange rate to amount and return a new Money in the toCurrency.

The Currency of the amount must be the same as the fromCurrency otherwise a MismatchedCurrencyException is thown.

Implementation

Money applyRate(Money amount) {
  if (fromCurrency != amount.currency) {
    throw MismatchedCurrencyException(
        expected: fromCurrency.isoCode, actual: amount.currency.isoCode);
  }

  /// convertedUnits now has this.decimalDigits + exchangeRate.decimalDigits
  /// decimal digits.
  final convertedUnits = amount.amount * exchangeRate;

  return Money.fromFixed(convertedUnits,
      isoCode: toCurrency.isoCode,
      decimalDigits: toDecimalDigits ?? toCurrency.decimalDigits);
}