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?

Currency Predicates

To check that money value has an expected currency use the methods isInCurrency(Currency) and isInSameCurrencyAs(Money):

import 'package:money2/money2.dart';
test('isInCurrency', () {
      final fiveDollars = Money.parse('5.00', isoCode: 'USD');
      final sevenDollars = Money.parse('7.00', isoCode: 'USD');
      final fiveEuros = Money.parse('5.00', isoCode: 'EUR');
      expect(fiveDollars.isInCurrency(CommonCurrencies().usd.isoCode),
          isTrue); // => true
      expect(fiveDollars.isInCurrency(CommonCurrencies().euro.isoCode),
          isFalse); // => false
      expect(fiveDollars.isInSameCurrencyAs(sevenDollars), isTrue); // => true
      expect(fiveDollars.isInSameCurrencyAs(fiveEuros), isFalse); // => false
    });
PreviousComparisonNextValue Sign Predicates

Last updated 29 days ago

Was this helpful?