Classic Computer Magazine Archive COMPUTE! ISSUE 39 / AUGUST 1983 / PAGE 163

Neat Numbers On The VIC

Daniel E. Dick

These subroutines will print numbers and display calculations on a TV or a printer in easily read columns. There are several solutions here to common formatting problems.

I use a VIC-20 and VIC-1515 printer in designing programs for my work in energy studies. I find that the familiar TAB and the CHR$(16) functions leave something to be desired when you are sending numbers to a monitor or printer. Both TAB and CHR$ left justify columns of numbers. The VIC-20 also does not include a PRINT USING statement for right justifying columns of numbers or for placing commas between numerical units in the thousands.

As you can see from these examples:
99999 is more easily read as 99,999
12345678 is more easily read as 12,345,678

And a column of numbers is more easily read (and checked for addition) if it is right justified as well. The column of numbers to the right is easier to read and total:

50.65 50.65
1.10 1.10
250.40 250.40
2500.00 2500.00

Program 1 is a short and simple program to right justify and display real numbers on the screen.

Input Output
.01 .01
.1 .1
1 1
1.2 1.2
1.21 1.21
11 11
11.2 11.2
11.21 11.21
111 111
111.21 111.21

Program 2 right justifies and prints integers up to 999999999 (999,999,999) – VIC's limit of standard notation.

INPUT OUTPUT
9 9
99 99
999 999
9999 9,999
99999 99,999
999999 999,999
9999999 9,999,999
99999999 99,999,999
999999999 999,999,999

Program 3 right justifies and prints real numbers up to 9999999.99 (9,999,999.99) which is the limit of standard notation in the VIC-20.

INPUT OUTPUT
.09 .09
.9 .90
9 9.00
9.99 9.99
99 99.00
99.99 99.99
999 999.00
9999 9,999.00
99999.5 99,999.50
999999 999,999.00
9999999 9,999,999.00

Program 4 displays and prints specific data and calculated results in a tabular form that is legible and understandable. Programs 2 and 3 have been integrated into the main program in lines 5000-5050 and 5100-5180.

Lines 10000-10050 are a helpful subroutine for renumbering lines (published in COMPUTE!, April 1982).

Your Energy Consumption For Space Heat During Year Chosen:

NO. UNITS UNIT FUEL UNIT COST FUEL COST
1,100.00 GALS OIL 1.27 1,397.00
1,450.00 CCF NATURALGAS .65 942.50
12,345.00 KWH ELECTRICITY .09 1,111.05
5.50 CORDS WOOD 95.00 522.50
4.75 TONS COAL 166.00 788.50
TOTAL COST $4,761.55
NO. UNITS UNIT FUEL BTU/UNIT BTU'S CONSUMED
1,100.00 GALS OIL 140,000 154,000,000
1,450.00 CCF NATURALGAS 100,000 145,000,000
12,345.00 KWH ELECTRICITY 3,414 42,145,830
5.50 CORDS WOOD 20,000,000 110,000,000
4.75 TONS COAL 20,000,000 95,000,000
TOTAL 546,145,830

Program 5 brings us back full circle to Program 1, with line 15 transferring control to the printer.

OUTPUT
.01
.1
1
10
100
1000