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) → doubleThis operator-addition operator of double addition operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the number to be added to this number |
✐ Examples
1 Add two numbers (3.5 + 2.5)
In this example,
- We use the `+` operator to add
3.5and2.5. - The result is stored in the variable
result. - 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,
- We define two variables
aandbwith values10.0and5.5respectively. - We then use the `+` operator to add
aandb. - The result is stored in the variable
result. - 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,
- We use the `+` operator to add
-2.0and7.0. - The result is stored in the variable
result. - 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.