Parsing
Money.parse
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
Currencies.parse
If you got this far you deserve a prize.
Last updated
Was this helpful?