Overview
Arithmetic operators allow you to perform mathematical calculations in Dart. These operators work with numeric types likeint and double.
Arithmetic Operators Table
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 3 | 13 |
- | Subtraction | 10 - 3 | 7 |
* | Multiplication | 10 * 3 | 30 |
/ | Division (returns double) | 10 / 3 | 3.333... |
~/ | Integer Division | 10 ~/ 3 | 3 |
% | Modulo (remainder) | 10 % 3 | 1 |
The
~/ operator performs integer division and returns only the whole number part, discarding any remainder.Basic Example
Here’s a complete example demonstrating all arithmetic operators:Key Differences
Division (/) vs Integer Division (~/)
The key difference between these two operators:
- Division (
/): Returns adoublewith the exact result including decimals - Integer Division (
~/): Returns anintwith only the whole number part