# Parsing

The Money package provides a number of methods to parse a monetary amount:

* Money.parse
* Currency.parse
* Currencies.parse

You may also find Fixed.parse is useful for parsing decimal values which can then be used to create a Money instance.

### Money.parse

Allows you to parse a string containing a monetary amount.

When using Money.parse you must know the currency of the monetary amount.

```dart
import 'package:money2/money2.dart';
import 'package:test/test.dart';

void main() {
  test('Parse money', () {
      /// Parse the amount using default pattern for AUD.
      final t1 = Money.parse('10.00', isoCode: 'AUD');
      expect(t1.toString(), equals(r'$10.00'));

      final t2 = Money.parse(r'$10.00', isoCode: 'AUD');
      expect(t2.amount, equals(Fixed.fromNum(10.00)));

      /// Parse using an alternate pattern
      final t3 =
          Money.parse(r'$10.00 AUD', isoCode: 'AUD', pattern: 'S0.00 CCC');
      expect(t3.amount, equals(Fixed.parse('10.00', scale: 2)));
    });
}

```

### Currency.parse

Parse a monetary amount for a known currency.

```dart
import 'package:money2/money2.dart';
import 'package:test/test.dart';

void main() {

  test('parse with Currency', () {
   /// Parse using a currency.
   final t1 = CommonCurrencies().aud.parse(r'$10.00');
   expect(t1.toString(), equals(r'$10.00'));
   expect(t1.currency.isoCode, equals('AUD'));
  });
}
```

### Currencies.parse

Allows you to parse a monetary amount using an embedded currency code to derive the currency.

```dart
import 'package:money2/money2.dart';
import 'package:test/test.dart';

void main() {

      test('parse with unknown currency', () {
            final t1 = Currencies().parse(r'$AUD10.00');
            expect(t1.toString(), equals(r'$10.00'));
            expect(t1.currency.isoCode, equals('AUD'));
      });
}
```

## If you got this far you deserve a prize.

If you have enough money it's good to tout.

But a word to the unwise.

Spending it gladly can lead to a drought.

##


---

# 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/parsing.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.
