exchangeTo method
Converts a Money instance into a new Money instance
with its Currency defined by the exchangeRate
.
The current Money amount is multiplied by the exchange rate to arrive at the converted currency.
e.g. US$0.68 = AU$1.00 * US$0.6800
Where US$0.68 is the exchange rate.
In the below example we do the following conversion: $10.00 * 0.68 = $6.8000
To do the above conversion:
Currency aud = Currency.create('AUD', 2);
Currency usd = Currency.create('USD', 2);
Money invoiceAmount = Money.fromInt(1000, aud);
Money auToUsExchangeRate = Money.fromInt(68, usd);
Money usdAmount = invoiceAmount.exchangeTo(auToUsExchangeRate);
Implementation
Money exchangeTo(ExchangeRate exchangeRate) => exchangeRate.applyRate(this);