compareTo method

  1. @override
int compareTo(
  1. Decimal other
)
override

Compare two Decimals
NOTES:

  • This comparison ignores trailing zeros. If you need strict equality (including scale), use strictEquals method.
  • If other is a Rational, it will be converted to Rational for comparison.

Implementation

@override
int compareTo(Decimal other) {
  final otherOptional = other.toRational();

  final crossProduct1 = _numerator * otherOptional._denominator;
  final crossProduct2 = otherOptional._numerator * _denominator;
  return crossProduct1.compareTo(crossProduct2);
}