fixed
  • Overview
  • Constructors
  • Scale
  • Parsing
  • Formatting
  • Performing math
  • Comparison
  • Storing
Powered by GitBook
On this page

Was this helpful?

Comparison

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));
PreviousPerforming mathNextStoring

Last updated 2 years ago

Was this helpful?