Classic Computer Magazine Archive ANTIC VOL. 7, NO. 4 / AUGUST 1988


Dollars and cents where you want them

NumberPrint is a clever, handy subroutine that correctly lines up numbers for neat printouts. It automatically sets right justification for proper column alignment, floating dollar signs and commas, and filler characters for check printing. This BASIC program works on all 8-bit Atari computers of any memory size, with disk or cassette.

Want to spruce up your program's reports? How about printing numbers using floating dollar signs, commas, and fill characters? No more checking numbers to see if you need to precede them with blanks, so that your amounts print out correctly in columns. No more converting numbers into string format and struggling to right-justify them so that the cents don't end up where dollars should be.

NumberPrint knows where to place numbers for correct printouts. All you have to do is create an edit pattern and call the NumberPrint subroutine from your main program.

Getting Started

Type in Listing 1, NUMPRINT.BAS, check it with TYPO II and SAVE a copy before you RUN it. (Antic Disk owners will also find a bonus file this month, NUMPRINT.M65, the MAC/65 assembly language source code for NumberPrint.)

If you have trouble typing the special characters in lines 1010-1040, don't type them in. Instead, type in Listing 2, check it with TYPO II and SAVE a copy. When you RUN Listing 2, it creates these hard-to-type lines and stores them in a file called LINES.LST.

To merge the two programs, disk users LOAD "D:NUMPRINT.BAS" and then ENTER "D:LINES.LST." Cassette users: CLOAD Listing 1, then insert the separate cassette used for Listing 2 and ENTER "C:' Remember to SAVE the completed program before you RUN it.

The table below shows how NumberPrint translates the proper edit pattern into the printed result you want.

     Number     Edit Pattern     Result
       10       "XX,XXX.XX"    "    10.00"
       22.5     "X$,XXX.XX"    "   $22.50"
        5       "**,XXX.XX"    "*****5.00

You must first place the subroutine's data into a string. Now you will need a string where your edited number will be placed. Fill this string with the desired pattern. You will also need a temporary variable for the subroutine to use. Place the number you wish to edit into the temporary variable and then call the USR function. Your number is now in the string and ready to print.

Setting up your own edit pattern is easy. Use the X character for each spot where you wish a digit to be placed. Use as many Xs as the largest number you will use. If your number will contain fractions (decimal places) you can use the optional period [.] character. Place the period at the left of the digits that will represent it. The subroutine will fill these positions with zeros if your number has no fractions.

Fractions will be dropped if no period is in the string. Note that no rounding-off is performed. Commas or any other characters (except for optional and inverse) can be placed anywhere in the string to separate digits.

NumberPrint has two other optional characters which you can include – the dollar sign [$] and the asterisk [*]. These characters, if placed in the second position in the string, will automatically float up to the most significant digit. This is very useful if your program is printing checks.

Another handy way to use NumberPrint is for placing filler characters. The default character is a blank. Place the desired character in the first position of the string and if the number is smaller than the digits in the string, the spaces will be replaced with this character. Note that use of either the float position or the fill position takes the place of one of your X's. This means that if your number is too large, it will cut off these options. If you always wish to have these options in effect you should have enough Xs to fill in the string completely.

Marc Escola of Portland, Oregon is senior application programmer for a major retail company. A member of the Portland Atari Club he has been programming Atari 8-bit computers since 1983. This is his first publication in Antic.

Listing: NUMPRINT.BAS Download

On disk: NUMPRINT.M65 Download / View