Comment on page

# Comparison

Fixed supports a full set of comparison operators:

== - equals

< - less than

> - greater than

<= - less than or equal

>= - greater than or equal

!= - not equal

When comparing two Fixed values the two values will first be scaled so that both values have the same scale. The larger scale from the two values will be used.

Example 7

final t1 = Fixed.fromNum(1.23);

final t2 = Fixed.fromInt(123, scale: 2);

final t3 = Fixed.fromBigInt(BigInt.from(1234), scale: 3);

expect(t1 == t2, isTrue);

expect(t1 < t3, isTrue);

expect(t1 <= t3, isTrue);

expect(t1 > t3, isFalse);

expect(t1 >= t3, isFalse);

expect(t1 != t3, isTrue);

expect(-t1, equals(Fixed.fromInt(-123, scale: 2)));

expect(t1.isPositive, isTrue);

expect(t1.isNegative, isFalse);

expect(t1.isZero, isFalse);

Fixed also supports the compareTo method allowing Fixed values to be sorted.

expect(t1.compareTo(t2), equals(0));

Last modified 1yr ago