Dart double operator-addition
Syntax & Examples


double.operator-addition operator

The `+` operator is used for addition, which adds two numbers together.


Syntax of double.operator-addition

The syntax of double.operator-addition operator is:

operator +(num other) → double

This operator-addition operator of double addition operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe number to be added to this number


✐ Examples

1 Add two numbers (3.5 + 2.5)

In this example,

  1. We use the `+` operator to add 3.5 and 2.5.
  2. The result is stored in the variable result.
  3. We print the result to standard output.

Dart Program

void main() {
  double result = 3.5 + 2.5;
  print('Result: $result');
}

Output

Result: 6.0

2 Add two variables (a + b)

In this example,

  1. We define two variables a and b with values 10.0 and 5.5 respectively.
  2. We then use the `+` operator to add a and b.
  3. The result is stored in the variable result.
  4. We print the result to standard output.

Dart Program

void main() {
  double a = 10.0;
  double b = 5.5;
  double result = a + b;
  print('Result: $result');
}

Output

Result: 15.5

3 Add a negative and a positive number (-2.0 + 7.0)

In this example,

  1. We use the `+` operator to add -2.0 and 7.0.
  2. The result is stored in the variable result.
  3. We print the result to standard output.

Dart Program

void main() {
  double result = -2.0 + 7.0;
  print('Result: $result');
}

Output

Result: 5.0

Summary

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