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.

Please follow and like us:

About the Author

billm

A.P.P.L.E. Chairman of the Board and Club president — Bill worked for the founder, Val J. Golding and A.P.P.L.E. from 1981 to 1982. In 1999, he began archiving the materials which were distributed and sold by A.P.P.L.E.. That project led to the group that remained of A.P.P.L.E. Bill was involved in the financial industry in Tokyo and has over 20 major office infrastructure projects to his name. In March 2001, he retired to write books and to spend more time pursuing personal interests. As the president of the users group, Bill is in charge of distribution of Call-A.P.P.L.E. magazine as well as the organization of this web site. Bill currently resides in Tokyo, Japan and Shelton, Wa splitting time between the places.