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,

  1. We create a double variable num with the value -10.0.
  2. We use the isNegative property to check if num is negative.
  3. 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,

  1. We create a double variable positiveNum with the value 5.0.
  2. We use the isNegative property to check if positiveNum is negative.
  3. 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,

  1. We create an integer variable zero with the value 0.
  2. We use the isNegative property to check if zero is negative.
  3. 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.