~/ operator performs truncating division. It divides two numeric operands (dividend and divisor) and returns the integer quotient, discarding any fractional remainder.
Syntax
Operational Semantics
- Return Type: The operator always returns an
int. - Rounding Behavior: The result is truncated towards zero. This is equivalent to calculating the standard division result and casting it to an integer (
(a / b).toInt()).- Positive results are rounded down (e.g.,
3.9becomes3). - Negative results are rounded up (e.g.,
-3.9becomes-3).
- Positive results are rounded down (e.g.,
- Exception Handling:
- Integer Operands: If both operands are integers and the divisor is
0, the operation throws anIntegerDivisionByZeroException. - Double Operands: If any operand is a
doubleand the result is not a finite number (e.g., dividing by zero resulting in Infinity, or0.0 ~/ 0.0resulting in NaN), the operation throws anUnsupportedError. This occurs becauseInfinityandNaNcannot be represented as anint.
- Integer Operands: If both operands are integers and the divisor is
Examples
The following code demonstrates the behavior of the~/ operator with integers, doubles, and negative numbers.
Master Dart with Deep Grasping Methodology!Learn More





