ID: Q111321
The information in this article applies to:
The STR() function rounds instead of truncates a numeric field or variable if the result being returned has fewer decimal places than the original numeric expression.
There is a mistake in the documentation for the STR() function.
This behavior is by design.
According to the online Help file and the "Language Reference" (page L3-1054 for Windows and MS-DOS and page 835 for the Macintosh), if you use the STR() function and specify fewer decimal places than in the original numeric expression, the extra digits are truncated. In fact, the string will be reduced to the specified number of digits, but the decimals will have been rounded rather than truncated.
To duplicate this scenario, type the following code at the Command window:
? STR(123.456,6,2)
This command line specifies that we want the string returned with six total
digits including two decimal places. The original numeric expression has
three decimal places.
A true truncation would return 123.45; however, FoxPro will return 123.46. The expression has been reduced to the correct number of digits, but the value has been rounded instead of truncated.
Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b transform picture number docerr tshoot KBCategory: kbprg kbprb kbdocerr KBSubcategory: FxprgGeneral
Last Reviewed: June 27, 1995