Syntax

Divides two numbers. / keeps the decimals; DIV keeps only the whole part, cut toward zero.

<a> DIV <b>
<a> / <b>

Also written : /, integer division

Parts

<a>The number to divide. For DIV: a number, a variable without sigil, an array cell, a record field, or a group in parentheses.
<b>The divisor. For DIV: a number, possibly with a minus sign, a variable without sigil, an array cell or a record field.

Good to know

  • / always keeps the decimals, even between two integers: 7 / 2 is 3.5. Dividing by zero with / gives Infinity.
  • DIV cuts toward zero: -7 DIV 2 is -3, 7.5 DIV 2.5 is 3. Dividing by zero stops the program with BASIC integer division by zero.
  • DIV is done before * and /: 2 * 7 DIV 2 is 2 * 3, so 6.
  • Defect: after a + or -, DIV breaks the program. h = 10 + 9 DIV 2 and h = 10 - x DIV 2 compile, but the program does not start. Put the DIV in parentheses, 10 + (9 DIV 2), or write it first, 9 DIV 2 + 10.
  • After a command call it breaks the program too: Len(s$) DIV 2 compiles but does not start. Before a group in parentheses it is refused: a DIV (b - 1) gives Unknown BASIC command: DIV(). Put the call or the group in a variable first.
  • Defect: a variable with a sigil on the left breaks the program: z# DIV 2 compiles but does not start. Write (z#) DIV 2.
  • MOD is not an operator: 7 MOD 2 is refused. Use Mod() for the remainder, FMod() for decimals. The backslash of other BASICs, a \ b, compiles but the program does not start: write a DIV b.
  • With int64 values, DIV divides exactly as whole numbers.

Example

a = 7b = 2Console(Str(a / b))   ' 3.5Console(Str(a DIV b))   ' 3Console(Str(-7 DIV 2))   ' -3h = 10 + (a DIV b)Console(Str(h))   ' 13
In the manual : Constants and operators

Commands that go with it