The `isNegative` property in Dart checks whether a number is negative.
The syntax of double.isNegative property is:
bool isNegative
This isNegative property of double true if the number is negative; otherwise, false.
double.isNegative returns value of type bool
.
In this example,
num
with the value -10.0.isNegative
property to check if num
is negative.void main() {
double num = -10.0;
bool negative = num.isNegative;
print('Is $num negative? $negative');
}
Is -10 negative? true
In this example,
positiveNum
with the value 5.0.isNegative
property to check if positiveNum
is negative.void main() {
double positiveNum = 5.0;
bool negative = positiveNum.isNegative;
print('Is $positiveNum negative? $negative');
}
Is 5 negative? false
In this example,
zero
with the value 0.isNegative
property to check if zero
is negative.void main() {
int zero = 0;
bool negative = zero.isNegative;
print('Is $zero negative? $negative');
}
Is 0 negative? false
In this Dart tutorial, we learned about isNegative property of double: the syntax and few working examples with output and detailed explanation for each example.