home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-386-Vol-2of3.iso
/
b
/
baswiz19.zip
/
BW$BAS.ZIP
/
BCDFORM.BAS
< prev
next >
Wrap
BASIC Source File
|
1993-01-29
|
2KB
|
56 lines
' +----------------------------------------------------------------------+
' | |
' | BASWIZ Copyright (c) 1990-1993 Thomas G. Hanlin III |
' | |
' | The BASIC Wizard's Library |
' | |
' +----------------------------------------------------------------------+
DECLARE SUB BCDGetSize (LeftDigits AS INTEGER, RightDigits AS INTEGER)
DEFINT A-Z
FUNCTION BCDFormat$ (Nr AS STRING, FormatType%, RightDigits%)
BCDGetSize LeftD, RightD
Sign$ = LEFT$(Nr, 1)
L$ = MID$(Nr, 2, LeftD)
R$ = RIGHT$(Nr, RightD)
WHILE LEFT$(L$, 1) = CHR$(0)
L$ = MID$(L$, 2)
WEND
IF L$ = "" THEN L$ = CHR$(0)
IF FormatType AND 1 AND (LEN(L$) > 3) THEN
t$ = LEFT$(L$, LEN(L$) - 3)
L$ = RIGHT$(L$, 3)
WHILE LEN(t$) > 3
L$ = RIGHT$(t$, 3) + "," + L$
t$ = LEFT$(t$, LEN(t$) - 3)
WEND
L$ = t$ + "," + L$
IF LEFT$(L$, 1) = "," THEN L$ = MID$(L$, 2)
END IF
IF FormatType AND 2 THEN L$ = "$" + L$
IF FormatType AND 8 AND (Sign$ = " ") THEN Sign$ = "+"
R$ = LEFT$(R$, ABS(RightDigits))
IF RightDigits < 0 THEN
WHILE RIGHT$(R$, 1) = CHR$(0)
R$ = LEFT$(R$, LEN(R$) - 1)
WEND
END IF
IF FormatType AND 4 THEN
R$ = R$ + Sign$
ELSE
L$ = Sign$ + L$
END IF
St$ = L$ + "." + R$
IF RightDigits = 0 THEN
tmp = INSTR(St$, ".")
St$ = LEFT$(St$, tmp - 1) + MID$(St$, tmp + 1)
END IF
FOR tmp = 1 TO LEN(St$)
ch = ASC(MID$(St$, tmp, 1))
IF ch < 10 THEN MID$(St$, tmp, 1) = CHR$(ch + 48)
NEXT
BCDFormat$ = St$
END FUNCTION