Skip to main content
The division operator (/) calculates the standard quotient of two numbers. It is a binary operator that accepts operands of type num (covering both int and double) and invariably returns a result of type double.

Syntax

double result = dividend / divisor;

Type Resolution

In Dart, the / operator does not perform truncating integer division, even if both operands are integers.
Operand A TypeOperand B TypeReturn TypeExampleResult
intintdouble10 / 25.0
doubleintdouble10.0 / 25.0
intdoubledouble10 / 2.54.0

Compile-Time Constants

If the operands are compile-time constants, the result of the division is also treated as a compile-time constant, provided the operation does not result in an error.
const double a = 10 / 2; // Valid constant assignment

Special Values (IEEE 754)

The operator adheres to IEEE 754 floating-point arithmetic standards regarding special values:
  • Infinity: Dividing a non-zero number by zero results in Infinity or -Infinity. It does not throw an exception.
  • NaN (Not a Number): Dividing 0 by 0 (or 0.0 by 0.0) results in NaN.
print(1 / 0);  // Output: Infinity
print(-5 / 0); // Output: -Infinity
print(0 / 0);  // Output: NaN

Distinction from Truncating Division

To perform division that returns an integer (truncating the fractional part), Dart provides the ~/ operator. The / operator preserves the fractional component.
var standard = 5 / 2;   // 2.5 (double)
var truncated = 5 ~/ 2; // 2   (int)
Master Dart with Deep Grasping Methodology!Learn More