Microsoft KB Archive/96359

{| = Using SET DECIMALS and ROUND for Specific # of Decimals =
 * width="100%"|

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.

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.