In QuickBASIC, the MOD remainder operator, like the backslash operator, also uses integer division with rounding in calculations.

Keep this in mind if you are porting some old QuickBASIC code that uses the MOD remainder operator.

`DIM AS DOUBLE Dbl1 = 19.0`

DIM AS DOUBLE Dbl2 = 6.7

DIM AS DOUBLE RetDbl

PRINT

PRINT " MOD Remainder Operator"

PRINT " 19.0 MOD 6.7"

' BCX MOD function

RetDbl = MOD(Dbl1, Dbl2)

PRINT RetDbl, " BCX MOD function "

' BCX IMOD function

DIM Int1%

DIM Int2%

DIM RetInt%

Int1% = INT(Dbl1)

Int2% = INT(Dbl2)

RetInt% = IMOD(Int1%, Int2%)

PRINT RetInt%, " BCX IMOD function "

' QuickBASIC MOD function as Brute Force BCX

DIM QBMOD%

Int1% = INT(ROUND(Dbl1, 0))

Int2% = INT(ROUND(Dbl2, 0))

QBMOD% = IMOD(Int1%, Int2%)

PRINT QBMOD%, " Brute Force BCX QuickBASIC MOD equivalent"

' QuickBASIC MOD function as BCX equivalent

' derived from rpgfan3233 post @

' https://www.tapatalk.com/groups/qbasic/modulo-and-remainder-functions-t31093.html

QBMOD% = Dbl1 - INT(Dbl1 / Dbl2) * Dbl2

PRINT QBMOD%, " rpgfan3233 QuickBASIC MOD equivalent"

Results:

` MOD Remainder Operator`

5.6 BCX MOD function

1 BCX IMOD function

5 Brute Force BCX QuickBASIC MOD equivalent

5 rpgfan3233 QuickBASIC MOD equivalent