Microsoft KB Archive/99611

{| = Using Variable Decimal Places in Report Writer =
 * width="100%"|

ID: Q99611

The information in this article applies to:


 * Microsoft FoxPro for Windows, versions 2.5 and 2.5a
 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a

SUMMARY
By using report variables as described below, you can eliminate trailing zeros after the decimal instead of printing a fixed number of characters after the decimal.

MORE INFORMATION
The following steps create a report that always prints the first decimal place but does not print trailing zeros beyond the first decimal place:

1. Create a database with one numeric field called Number; length=10,

decimals=4. 2. Add sample data to the database; some of the numbers should have zeros at the end; some should not. For example, 1.1000, 1.1200, 1.1230, 1.1234. 3. Create a quick report based on this database. 4. Create the following report variables (all variables have an initial

value of 0 [zero] and no calculation). The variables should appear in  the variable list in the same order they are given below.

Variable name Value to store

place4        IIF(VAL(RIGHT(STR(number,10,4),1))>0,1,0) place3        IIF(place4=1 OR                        VAL(RIGHT(STR(number,10,3),1))>0,1,0) place2        IIF(place3=1 OR                        VAL(RIGHT(STR(number,10,2),1))>0,1,0) numplaces     1+place2+place3+place4 5. Close the Report Variable dialog box and modify the report expression containing the numeric field so that is left-aligned and contains the following expression:

STR(number,5+numplaces,numplaces).

To left-align the field in FoxPro for MS-DOS:

- Select the Style check box while in the Report Expression dialog box, then choose Left Alignment.

To left-align the field in FoxPro for Windows:

- Select the field on the report, then choose Alignment and Left from the Object menu.

NOTE: &quot;5+numplaces&quot; along with left-aligning the field will ensure that the decimals are aligned. If this is not important, &quot;5+numplaces&quot; can be  changed to &quot;10&quot; (without the quotation marks)--the full length of the field. 6. From the Report menu, choose Page Preview to see the output without trailing zeros beyond the first decimal place. Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a KBCategory: kbprint kbprg KBSubcategory: FxprintGeneral
 * }