# Exchange Rates

When manipulating monetary amounts you often need to convert between currencies.

Money2 provide a simple method to convert a `Money` instance to another currency using an exchange rate.

To converts a `Money` instance into a target `Currency` use the `Money.exchangeTo` method and an ExchangeRate.

To do this you need to define an exchange rate which consists of a rate, a from currency and a to currency.&#x20;

### Example

Lets say you have an invoice in Australian Dollars (AUD) which you need to convert to US Dollars (USD).

Start by googling the exchange rate for AUD to USD. You are likely to find something similar to:

1 AUD = 0.68c USD

Which means that for each Australian Dollar you will receive 0.68 US cents. (AKA I'm not traveling to the USA this year).

To do the above conversion:

```dart
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'));
    });
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://money2.onepub.dev/exchange-rates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
