08-25-2022, 01:45 AM
Code: (Select All)
'this allows a negative value padded by zeroes after sign
'set "numdig" to negative value to convert "num" to hexadecimal
'eg. "numdig = -6" to convert "num" to 6-digit hexadecimal string
FUNCTION Zeroes$ (num AS LONG, numdig AS INTEGER)
STATIC b$, hx AS _BYTE, sg AS _BYTE, numd AS INTEGER, numi AS LONG, v AS LONG
numi = num: numd = numdig
IF numi < 0 THEN sg = -1: numi = numi * -1
IF numd < 0 THEN hx = 1: numd = numd * -1 ELSE hx = 0
IF hx THEN
b$ = HEX$(numi)
ELSE
b$ = LTRIM$(STR$(numi))
END IF
v = numd - LEN(b$)
IF v > 0 THEN b$ = STRING$(v, 48) + b$
IF sg = -1 THEN b$ = "-" + b$
Zeroes$ = b$
END FUNCTION
I needed it even more with hexadecimal numbers.