'===========================================================================
' Subject: CURRENCY CODE                      Date: 09-19-98 (17:03)       
'  Author: Robert P. Schumaker                Code: QB, QBasic, PDS        
'  Origin: cubix@tusco.net                  Packet: MISC.ABC
'===========================================================================
REM ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
REM ³Program: Currency Code             ³
REM ³                                   ³
REM ³Author: Robert P. Schumaker        ³
REM ³                                   ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
REM ³History: Ver 1.00 (9/19/98) Basic Program          ³
REM ³                                                   ³
REM ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

' Here's a simple little code to help translate ordinary numbers into the
' currency format.  It may not be pretty or elegant however it is quite
' functional.

' This code works by taking a number multiplied by 100 and then passing it
' through the dlrformat function.  The dlrformat function then takes the
' number and makes it into a string in the currency format.

DECLARE FUNCTION dlrformat$ (PassThru AS DOUBLE)

CLS : PRINT "Give me a number to convert into a currency..."
INPUT "i.e.(523.2 or 231 or 312.453): "; string1
PRINT : PRINT "$"; dlrformat(string1 * 100)

DEFINT A-Z
FUNCTION dlrformat$ (PassThru AS DOUBLE) STATIC

' Note: the PassThru must be multiplied by 100, If you wanted $3.12 to appear
' then the PassThru would be 312.

Remainder = INT((PassThru - INT(PassThru)) * 10)
IF Remainder > 4 THEN PassThru# = PassThru# + 1
Acrue# = INT(PassThru#) / 100
Acrue$ = LTRIM$(STR$(Acrue#))
LenPassThru = LEN(LTRIM$(STR$(PassThru#)))
Acrue$ = MID$(Acrue$, 1, LenPassThru + 1)
LenAcrue = LEN(Acrue$)
IF LenPassThru = LenAcrue THEN Acrue$ = Acrue$ + "0"
IF LenPassThru = 1 THEN Acrue$ = "0" + LTRIM$(STR$(Acrue#))
IF LenPassThru = LenAcrue + 2 THEN Acrue$ = Acrue$ + ".00"
IF MID$(Acrue$, 1, 1) = "." THEN Acrue$ = "0" + Acrue$
IF Acrue# = 0 THEN Acrue$ = "0.00"
stringchk = 1
DO UNTIL MID$(Acrue$, stringchk, 1) = "."
        stringchk = stringchk + 1
        LOOP
IF LEFT$(RIGHT$(Acrue$, 3), 1) <> "." THEN Acrue$ = Acrue$ + "0"
dlrformat$ = LEFT$(Acrue$, stringchk + 2)
END FUNCTION
