# Routine to Format Decimal Numbers

10 REM ROUTINE TO FORMAT DECIMALNUMBERS ROUNDED OFF TO TWO PLACES AND RIGHT JUSTIFIED BY BOB HUELSDONK
15 REM 4/27/78
20 REM APPLE PUGETSOUND PROGRAM LIBRARY EXCHANGE 6708 39TH AVE SW SEATTLE, WA. 98136
70 FOR I • 1 TO 10: READ A: P= A : GOSUB 6000
75 PRINT P\$: NEXT
80 END
90 DATA 56.2,23456.1,5,1.186,345.70,23,678.0123,-99999.889,.2389,789S67
100 REM
110 REM ” A.’ WAS CHANGED TO ‘P’
120 REM TO KEEP THE SUBROUTINE
130 REM ANONYMOUS.
140 REM WORKS FOR P<999999
150 REM BUT CAN BE INCREASED
6000 P\$ = STRS (P)
6010 FOR J = 1 TO LEN (\$). IF MID\$ (P\$,J,l) < > “.” THEN NEXT
6015 IF J = LEN (P\$) + 1 THEN P\$=p\$+”.”
6020 IF LEN (P\$) < J + 2 THEN 6040
6025 IF VAL ( MID\$ (P\$,J + 3,1) ) < 5 THEN 6035
6030 P\$= MID. (P\$,1,J + 1) + RIGHT\$( STR\$ ( VAL ( MID\$ (PI\$,J+2,1))+1),1)
6035 P\$ = MID\$ (P\$,1,J+2)
6040 IF LEN ( LEFTS (PS,J) ) > 7 THEN 6050
6045 P\$ =” ” + P\$: J = J + 1: GOTO 6040
6050 IF LEN (P\$) >=  9 THEN 6060
6055 P\$ = P\$ + “0” : GOTO 6050
6060 RETURN

l’hput P may be substituted for 90 DATA above, and other minor modifications made to suit your program. Save routiftes like the above cntd appeftd them to your programs.