Dart double sign
Syntax & Examples

double.sign property

The `sign` property returns the sign of the double's numerical value: -1.0 for negative values, 1.0 for positive values, and 0.0 for zero.


Syntax of double.sign

The syntax of double.sign property is:

 double sign 

This sign property of double returns the sign of the double's numerical value.

Return Type

double.sign returns value of type double.



✐ Examples

1 Check sign of a negative double

In this example,

  1. We define a double num with a value of -3.14.
  2. We access the sign property to obtain the sign of num.
  3. We print the sign value to standard output.

Dart Program

void main() {
  double num = -3.14;
  double signValue = num.sign;
  print('Sign of -3.14: $signValue');
}

Output

Sign of -3.14: -1

2 Check sign of a positive double

In this example,

  1. We define a double num with a value of 42.0.
  2. We access the sign property to obtain the sign of num.
  3. We print the sign value to standard output.

Dart Program

void main() {
  double num = 42.0;
  double signValue = num.sign;
  print('Sign of 42.0: $signValue');
}

Output

Sign of 42.0: 1

3 Check sign of zero

In this example,

  1. We define a double num with a value of 0.0.
  2. We access the sign property to obtain the sign of num.
  3. We print the sign value to standard output.

Dart Program

void main() {
  double num = 0.0;
  double signValue = num.sign;
  print('Sign of 0.0: $signValue');
}

Output

Sign of 0.0: 0

Summary

In this Dart tutorial, we learned about sign property of double: the syntax and few working examples with output and detailed explanation for each example.