Dart double isNegative
Syntax & Examples
double.isNegative property
The `isNegative` property in Dart checks whether a number is negative.
Syntax of double.isNegative
The syntax of double.isNegative property is:
bool isNegative
This isNegative property of double true if the number is negative; otherwise, false.
Return Type
double.isNegative returns value of type bool
.
✐ Examples
1 Check if a negative number is negative
In this example,
- We create a double variable
num
with the value -10.0. - We use the
isNegative
property to check ifnum
is negative. - We then print the result to standard output.
Dart Program
void main() {
double num = -10.0;
bool negative = num.isNegative;
print('Is $num negative? $negative');
}
Output
Is -10 negative? true
2 Check if a positive number is negative
In this example,
- We create a double variable
positiveNum
with the value 5.0. - We use the
isNegative
property to check ifpositiveNum
is negative. - We then print the result to standard output.
Dart Program
void main() {
double positiveNum = 5.0;
bool negative = positiveNum.isNegative;
print('Is $positiveNum negative? $negative');
}
Output
Is 5 negative? false
3 Check if zero is negative
In this example,
- We create an integer variable
zero
with the value 0. - We use the
isNegative
property to check ifzero
is negative. - We then print the result to standard output.
Dart Program
void main() {
int zero = 0;
bool negative = zero.isNegative;
print('Is $zero negative? $negative');
}
Output
Is 0 negative? false
Summary
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.