Comparison
Equality operator (
==
) returns true
when both operands are in the same currency and have an equal amount.import 'package:money2/money2.dart';
fiveDollars == fiveDollars; // => true
fiveDollars == sevenDollars; // => false
fiveDollars == fiveEuros; // => false (different currencies)
Money values can be compared with the
<
, <=
, >
, >=
operators, or the method compareTo()
from the interface Comparable<Money>
.These operators and method
compareTo()
can be used only between money values in the same currency. Runtime error will be thrown on any attempt to compare values in different currencies.import 'package:money2/money2.dart';
fiveDollars < sevenDollars; // => true
fiveDollars > sevenDollars; // => false
fiveEuros < fiveDollars; // throws ArgumentError!
Last modified 1yr ago