Dart double operator-subtraction
Syntax & Examples


double.operator-subtraction operator

The subtraction operator subtracts the given numeric value from another numeric value and returns a double result.


Syntax of double.operator-subtraction

The syntax of double.operator-subtraction operator is:

operator -(num other) → double

This operator-subtraction operator of double subtraction operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe numeric value to subtract


✐ Examples

1 Example with integer values

In this example,

  1. We create two integer values numValue1 and numValue2 with values 10 and 5 respectively.
  2. We then use the subtraction operator - to subtract numValue2 from numValue1.
  3. We print the subtraction result to standard output.

Dart Program

void main() {
  num numValue1 = 10;
  num numValue2 = 5;
  double result = numValue1 - numValue2;
  print('Subtraction result: $result');
}

Output

Subtraction result: 5.0

2 Example with floating-point values

In this example,

  1. We create two floating-point values numValue1 and numValue2 with values 3.5 and 2 respectively.
  2. We then use the subtraction operator - to subtract numValue2 from numValue1.
  3. We print the subtraction result to standard output.

Dart Program

void main() {
  num numValue1 = 3.5;
  num numValue2 = 2;
  double result = numValue1 - numValue2;
  print('Subtraction result: $result');
}

Output

Subtraction result: 1.5

3 Example with negative values

In this example,

  1. We create two numeric values numValue1 and numValue2 with values -8 and 4 respectively.
  2. We then use the subtraction operator - to subtract numValue2 from numValue1.
  3. We print the subtraction result to standard output.

Dart Program

void main() {
  num numValue1 = -8;
  num numValue2 = 4;
  double result = numValue1 - numValue2;
  print('Subtraction result: $result');
}

Output

Subtraction result: -12.0

Summary

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