Dart int sign
Syntax & Examples

int.sign property

The `sign` property in Dart returns the sign of this integer.


Syntax of int.sign

The syntax of int.sign property is:

 int sign 

This sign property of int returns the sign of this integer.

Return Type

int.sign returns value of type int.



✐ Examples

1 Sign of a positive integer

In this example,

  1. We create an integer variable number1 with the value 10.
  2. We access its sign property to get its sign.
  3. We then print the result to standard output.

Dart Program

void main() {
  int number1 = 10;
  int sign1 = number1.sign;
  print('Sign of $number1: $sign1');
}

Output

Sign of 10: 1

2 Sign of a negative integer

In this example,

  1. We create an integer variable number2 with the value -7.
  2. We access its sign property to get its sign.
  3. We then print the result to standard output.

Dart Program

void main() {
  int number2 = -7;
  int sign2 = number2.sign;
  print('Sign of $number2: $sign2');
}

Output

Sign of -7: -1

3 Sign of zero

In this example,

  1. We create an integer variable zero with the value 0.
  2. We access its sign property to get its sign.
  3. We then print the result to standard output.

Dart Program

void main() {
  int zero = 0;
  int signZero = zero.sign;
  print('Sign of $zero: $signZero');
}

Output

Sign of 0: 0

Summary

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