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 / 2is 3.5. Dividing by zero with/givesInfinity.DIVcuts toward zero:-7 DIV 2is -3,7.5 DIV 2.5is 3. Dividing by zero stops the program withBASIC integer division by zero.DIVis done before*and/:2 * 7 DIV 2is2 * 3, so 6.- Defect: after a
+or-,DIVbreaks the program.h = 10 + 9 DIV 2andh = 10 - x DIV 2compile, but the program does not start. Put theDIVin 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)givesUnknown 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 2compiles but does not start. Write(z#) DIV 2. MODis not an operator:7 MOD 2is refused. Use Mod() for the remainder, FMod() for decimals. The backslash of other BASICs,a \ b, compiles but the program does not start: writea DIV b.- With
int64values,DIVdivides 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)) ' 13In the manual : Constants and operators