The `isNegative` property checks whether a given big integer is negative.
The syntax of BigInt.isNegative property is:
bool isNegative
This isNegative property of BigInt whether this big integer is negative.
BigInt.isNegative returns value of type bool
.
In this example,
bigInt
with the value -12345.isNegative
property to check if the BigInt is negative. Since -12345 is negative, isNegative
returns true
.void main() {
BigInt bigInt = BigInt.from(-12345);
bool negative = bigInt.isNegative;
print('Is $bigInt negative? $negative');
}
Is -12345 negative? true
In this example,
bigInt
with the value 54321.isNegative
property to check if the BigInt is negative. Since 54321 is not negative, isNegative
returns false
.void main() {
BigInt bigInt = BigInt.from(54321);
bool negative = bigInt.isNegative;
print('Is $bigInt negative? $negative');
}
Is 54321 negative? false
In this example,
bigInt
with the value 0.isNegative
property to check if the BigInt is negative. Since 0 is not negative, isNegative
returns false
.void main() {
BigInt bigInt = BigInt.from(0);
bool negative = bigInt.isNegative;
print('Is $bigInt negative? $negative');
}
Is 0 negative? false
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.