PRB: STR() Rounds Instead of Truncating

Last reviewed: June 27, 1995
Article ID: Q111321
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for Macintosh, version 2.5b

SYMPTOMS

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.

CAUSE

There is a mistake in the documentation for the STR() function.

STATUS

This behavior is by design.

MORE INFORMATION

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.