Dart BigInt isNegative
Syntax & Examples

BigInt.isNegative property

The `isNegative` property checks whether a given big integer is negative.


Syntax of BigInt.isNegative

The syntax of BigInt.isNegative property is:

 bool isNegative 

This isNegative property of BigInt whether this big integer is negative.

Return Type

BigInt.isNegative returns value of type bool.



✐ Examples

1 Using a negative BigInt

In this example,

  1. We initialize a BigInt variable bigInt with the value -12345.
  2. We use the isNegative property to check if the BigInt is negative. Since -12345 is negative, isNegative returns true.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt bigInt = BigInt.from(-12345);
  bool negative = bigInt.isNegative;
  print('Is $bigInt negative? $negative');
}

Output

Is -12345 negative? true

2 Using a positive BigInt

In this example,

  1. We initialize a BigInt variable bigInt with the value 54321.
  2. We use the isNegative property to check if the BigInt is negative. Since 54321 is not negative, isNegative returns false.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt bigInt = BigInt.from(54321);
  bool negative = bigInt.isNegative;
  print('Is $bigInt negative? $negative');
}

Output

Is 54321 negative? false

3 Using zero BigInt

In this example,

  1. We initialize a BigInt variable bigInt with the value 0.
  2. We use the isNegative property to check if the BigInt is negative. Since 0 is not negative, isNegative returns false.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt bigInt = BigInt.from(0);
  bool negative = bigInt.isNegative;
  print('Is $bigInt negative? $negative');
}

Output

Is 0 negative? false

Summary

In this Dart tutorial, we learned about isNegative property of BigInt: the syntax and few working examples with output and detailed explanation for each example.