Unary Minus Operator

Dart Arithmetic Unary Minus Operator takes a single operand (on right side), and returns the negation of the the operand.

Symbol

- symbol is used for Unary Minus Operator.

Syntax

The syntax for Unary Minus Operator is

</>
Copy
- operand_1

Examples

Unary Minus of a Positive Number

In the following example, we take a positive number, and find its negation using Unary Minus operator.

main.dart

</>
Copy
void main() {
    var n = 25;
    var output = - n;
    print('-n = $output');
}

Output

-n = -25

Unary Minus of a Negative Number

In the following example, we take a negative number, and find its negation using Unary Minus operator.

main.dart

</>
Copy
void main() {
    var n = -74;
    var output = - n;
    print('-n = $output');
}

Output

-n = 74

Conclusion

In this Dart Tutorial, we learned how to use Arithmetic Unary Minus Operator to negate the sign of given number.