Classic Computer Magazine Archive COMPUTE! ISSUE 73 / JUNE 1986 / PAGE 11

Readers Feedback

The Editors and Readers of COMPUTE!

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

I am having difficulty formatting an amortization table on my PCjr that will display dollars to two decimal places (to the cents place). Currently, my program drops the trailing zeros following a decimal point. Do you have a solution for this?

Keith Bovee

The answer is to substitute PRINT USING for the more common PRINT statement. PRINT USING is very versatile and can be used to format the output of string or numeric data. The general format for this command is:

PRINT USING format$, expression(s)

    Replace format$ with a string constant or variable containing special formatting characters (listed in your BASIC manual). The formatting characters tell the computer exactly how it should print the expression that follows the semicolon. The expression may be either string or numeric data, and you may include more than one expression.
    Perhaps the most common use of PRINT USING is to format numeric data, a task that requires only two formatting characters. The number sign (#) reserves a digit position within the output string, and the dollar sign ($) stands for a dollar sign. For instance, type the following lines in direct mode (without line numbers):

X = 1234.00
PRINT USING "$####.##";X

    The first PRINT statement strips the decimal places, printing 1234. That's normal in BASIC, but undesirable in a program that requires dollars and cents format. The PRINT USING statement prints $1234.00 complete with a dollar sign and two decimal places. You can find additional examples of how to use PRINT USING in the IBM BASIC manual.