applyInverseRate method

Money applyInverseRate(
  1. Money amount
)

Applies the exchange rate in the reverse direction. The Currency of the amount must be the same as the toCurrency otherwise a MismatchedCurrencyException is thown.

Implementation

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

  return Money.fromFixedWithCurrency(
      amount.amount *
          Fixed.fromNum(1,
              scale: toDecimalDigits ?? toCurrency.decimalDigits) /
          exchangeRate,
      fromCurrency,
      decimalDigits: toDecimalDigits ?? toCurrency.decimalDigits);
}