Compucolor.org – Virtual Media

Listing of file='ROUND.BAS;01' on disk='vmedia/chip_128-sector.ccvf'

1000 REM    SUBROUTINE TO ROUND OFF AND JUSTIFY NUMBERS,
1010 REM         ADD COMMAS AND TRAILING ZEROS.
1020 REM
1030 REM  DEFINE X=NUMBER AND Z=LOCATION OF DECIMAL POINT
1040 REM          VALUE WILL BE RETURNED IN N$
1050 REM
1060 REM        OTHER VARIABLES USED ARE R1 AND R2
1070 REM
1080 REM  FOR EXAMPLE, X=2354.496 & Z=2 WILL RETURN WITH A
1090 REM           VALUE IN N$ OF N$=2,354.50
1100 REM
1110 REM
50000 X= INT ((X* 10^ Z)+ .5)/ 10^ Z:R1= 0:N$= "        "+ STR$ (X)
50010 N$= "       "+ N$
50020 FOR R2= 1TO LEN (N$)
50030 IF MID$ (N$,R2,1)= "."THEN R1= 5
50040 IF MID$ (N$,R2,1)= "."AND LEN (N$)- R2= ZTHEN R2= LEN (N$):NEXT :N$= RIGHT$ (N$,8):RETURN
50050 NEXT R2
50060 IF R1< > 5THEN N$= N$+ "."
50070 FOR R2= 1TO LEN (N$)
50080 IF MID$ (N$,LEN (N$)- R2+ 1,1)= "."THEN R1= R2
50090 NEXT R2
50100 IF Z= R1- 1GOTO 50130
50110 N$= N$+ "0":R1= R1+ 1
50120 IF Z< > R1- 1GOTO 50110
50130 N$= RIGHT$ (N$,8)
50140 IF Z= 0THEN N$= " "+ LEFT$ (N$,7)
50150 RETURN