money2
  • Overview
  • Common Currencies
  • Creating a Currency
  • Registering a Currency
  • Parsing
  • Find a currency
  • Default format
  • Symbols
  • Separators
    • Decimal Separator
    • Group Separator
  • Creating Money
    • Money.parse
    • Currency.parse
    • Money.from
    • Currencies.parse
    • decimalDigits
  • Formatting
    • Formatting Patterns
  • Storing and Send
  • Exchange Rates
  • Comparison
  • Currency Predicates
  • Value Sign Predicates
  • Arithmetic Operations
  • Allocation
  • Money encoding/decoding
Powered by GitBook
On this page

Was this helpful?

  1. Creating Money

Money.parse

Money.parse parses a string containing a monetary value.

Money.fromInt is faster if you already have the value represented as an integer in minor units.

The simplest variant of Money.parse relies on the default pattern of the passed currency.

import 'package:money2/money2.dart';   
test('Money.parse', () {
      final usd = Currency.create('USD', 2);
      final amount = Money.parseWithCurrency(r'$10.25', usd);
      expect(amount.currency.isoCode, equals('USD'));
    });

You can also pass an explicit pattern.

import 'money2.dart';
   test('Money.parse with Pattern', () {
      final usd = Currency.create('USD', 2);
      final amount = Money.parseWithCurrency(r'$10.25', usd, pattern: 'S0.00');
      expect(amount.currency.isoCode, equals('USD'));
    });
PreviousCreating MoneyNextCurrency.parse

Last updated 1 month ago

Was this helpful?