Skip to main content
The /= operator is a compound assignment operator in Dart that performs division and assignment in a single operation. It divides the value of the left operand by the value of the right operand and assigns the resulting floating-point quotient back to the left operand.
This syntax is semantically equivalent to:

Type Constraints and Behavior

In Dart, the standard division operator (/) strictly evaluates to a double, regardless of whether the operands are integers or floating-point numbers. Because the /= operator implicitly relies on /, it enforces specific type constraints on the left operand:
  1. Valid Types: The left operand must be declared as a double or the broader num type. If a num is initially assigned an integer, using /= will dynamically change its runtime type to double.
  2. Compile-Time Error: You cannot use the /= operator on a variable strictly typed as an int. Doing so results in a compile-time error: A value of type 'double' can't be assigned to a variable of type 'int'.

Syntax Visualization

(Note: If integer division assignment is required, Dart provides the ~/= operator, which performs truncating division and allows the left operand to remain an int.)
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More