; DECNUM
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Test function: print integer numbers with thousand separators;
; support three types of alignment: centered, left justified, right justified.
FUNCTION DecNum(n, j, l, s)
; Return number n justified in at least l characters according to j
; (0 = right justified, 1 = centered, other = left justified);
; s is used as thousand separator.
rn = REVERSE(n)
rl = STRLEN(rn)
c = LEFT(S, 1)
FOR x = 4 TO rl STEP 4
rn = INSERT(rn, x, c)
INC(@rl)
NEXT
rn = REVERSE(rn)
SWITCH j
ON 0
; Left justified
IF GT(l, rl)
rn = PADL(rn, l, " ")
FI
ON 1
; Centered
IF GT(l, rl)
rn = CENTER(rn, l)
FI
OTHER
; Right justified
IF GT(l, rl)
rn = PADR(rn, l, " ")
FI
OFF
RETURN rn