Ignoring the exchange rate
In order to just change the currency whilst ignoring the rate, the method exchange from the ConversionOperators
class can be used.
public class ExchangeRateProviderExample5 {
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
MonetaryOperator operator = ConversionOperators.exchange(dollar);
MonetaryAmount result = money2.with(operator).add(money);//USD 20.00000 ignoring currency
}
}