Using SET DECIMALS and ROUND() for Specific # of Decimals

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

SUMMARY

The SET DECIMALS command sets the minimum number of decimal places that will be displayed as a result of numeric functions and calculations. This setting will behave differently according to what operations are being performed. To ensure the output displays a specific number of decimal places, the ROUND() function should be used.

MORE INFORMATION

Sample Code

   a=1.2
   b=1.1
   SET DECIMALS TO 1
   ?a*b
   ?a/b
   SET DECIMALS TO 4
   ?a*b
   ?a/b
   ?ROUND(a*b,1)
   ?ROUND(a/b,1)
   ?ROUND(a*b,4)
   ?ROUND(a/b,4)

With SET DECIMALS TO 1, the expression a*b results in 1.32, and a/b results in 1.1. With SET DECIMALS TO 4, a*b results in 1.32 and a/b results in 1.0909. However, ROUND(a*b,1) results in 1.3, and ROUND(a/b,1) results in 1.1. Similarly, ROUND(a*b,4) results in 1.3200 and ROUND(a/b,4) results in 1.0909.

REFERENCES

"Language Reference," version 2.5, pages L3-836, L3-911

"Commands & Functions," version 2.0, pages C3-677, C3-740

"Commands & Functions," version 1.02, pages C3-291, C4-172


Additional reference words: FoxDos FoxWin 1.02 2.00 2.50 2.50a
KBCategory: kbprg 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.