Common Currencies

Money2 ships with a list of Common Currencies with a default format, decimals, isoCode and symbol.

If your currency isn't on the list then please help by submitting a PR.

The Common Currencies are pre-registered, allowing you to easily access them by their currency code or by a member field.

The $ character is used by Dart for String interpolation. When using a $ in a string mark the String as a raw or escape the $. e.g. `r'$1.00'` or `'\$1.00'`.

To create a Money instance from a common currency:

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

void main() {
  test('Common Currency - example 1', () {
    /// Create a Money instance from the AUD common currency.
    final amount = Money.parse(r'$1.25', isoCode: 'AUD');
    expect(amount.toString(), equals(r'$1.25'));
    expect(amount.format('SCCC 0.00'), equals(r'$AUD 1.25'));

    /// Create a Money instance using the aud field.
    final amount2 = Money.parseWithCurrency(r'$1.25', CommonCurrencies().aud);
    expect(amount2.format('SCC 0.00'), equals(r'$AU 1.25'));

    /// Create a money instance from a Fixed and the USD
    /// common currency.
    final amount3 = Money.fromFixed(Fixed.parse('1.24', scale: 2), isoCode: 'USD');

    expect(amount3.format('S0.00 CCC'), equals(r'$1.24 USD'));
  });
}

Here is the list of currencies available in CommonCurrenciesbut please check the CommonCurrencies class as the list is updated sporadically.

Last updated

Was this helpful?