Exchange Rates
Example
import 'package:money2/money2.dart';
import 'package:test/test.dart';
void main() {
test('exchange rate', () {
/// Create the AUD invoice amount ($10.00)
final invoiceAmount = Money.fromInt(1000, isoCode: 'AUD');
expect(invoiceAmount.format('SCCC 0.00'), equals(r'$AUD 10.00'));
/// Define the exchange rate in USD (0.68c)
final auToUsExchangeRate = ExchangeRate.fromFixed(
Fixed.parse('0.75432', scale: 5),
fromIsoCode: 'AUD',
toIsoCode: 'USD',
toDecimalDigits: 5);
expect(auToUsExchangeRate.format('0.00000'), equals('0.75432'));
/// Now do the conversion.
final usdAmount = invoiceAmount.exchangeTo(auToUsExchangeRate);
expect(usdAmount.format('SCCC 0.00'), equals(r'$USD 7.54'));
});
}Last updated
Was this helpful?