Dart num isNegative
Syntax & Examples
num.isNegative property
The `isNegative` property in Dart returns true if the number is negative; otherwise, it returns false.
Syntax of num.isNegative
The syntax of num.isNegative property is:
bool isNegative
This isNegative property of num true if the number is negative; otherwise, false.
Return Type
num.isNegative returns value of type bool
.
✐ Examples
1 Check negative number
In this example,
- We create a double variable
negativeNum
with the value -3.8. - We check if the number is negative using the
isNegative
property. - We then print the result to standard output.
Dart Program
void main() {
double negativeNum = -3.8;
bool isNegativeValue = negativeNum.isNegative;
print('Is $negativeNum negative? $isNegativeValue');
}
Output
Is -3.8 negative? true
2 Check positive number
In this example,
- We create a double variable
positiveNum
with the value 7.0. - We check if the number is negative using the
isNegative
property. - We then print the result to standard output.
Dart Program
void main() {
double positiveNum = 7.0;
bool isNegativeValue = positiveNum.isNegative;
print('Is $positiveNum negative? $isNegativeValue');
}
Output
Is 7 negative? false
Summary
In this Dart tutorial, we learned about isNegative property of num: the syntax and few working examples with output and detailed explanation for each example.