Div

From Free Pascal wiki
Jump to: navigation, search

Deutsch (de) English (en) français (fr)

Div is division in which the fractional part (remainder) is discarded. The expression (a div b) returns the integer part of the result of dividing two integers. This is in contrast to the expression (a / b) which returns a Real result. Both sides of an expression using div must be one of the integer types. Using a Real operand with div will result in a compile error: "Error: Operator is not overloaded:". To get an integer result with a Real operand, use Trunc or Round with the / operator.

Example:

var 
  i : ShortInt = 16; 
  j : ShortInt = 3;
  q : QWord = 1000;
  r : QWord = 300;
 
begin
  WriteLn(i div j);
  WriteLn(i / j);
  WriteLn(q div r);
  Writeln(q / r)
end.

Output:
5
 5.3333333333333330E+000
3
 3.3333333333333335E+000

See also