isZero property

bool get isZero

Returns true when the underlying number is numerically zero.

This is equivalent to this == 0, so it:

  • Works for both int and double (including 0 and 0.0).
  • Returns false for null (a null receiver is not considered zero).
  • Does not perform an epsilon / approximate comparison.

Examples:

int? a;            // null
double? b = 0.0;   // true
double? c = -0.0;  // true (because -0.0 == 0 evaluates to true)
int? d = 3;        // false

assert(a.isZero == false);
assert(b.isZero == true);
assert(c.isZero == true);
assert(d.isZero == false);

Implementation

bool get isZero => this == 0;