ACC: DSum Causes Rounding Error on Large Currency Fields (95/97)Last reviewed: December 16, 1997Article ID: Q177360 |
The information in this article applies to:
SYMPTOMSModerate: Requires basic macro, coding, and interoperability skills. Using the domain aggregate (totals) function DSum() to total a currency field may cause rounding errors for values exceeding fourteen significant digits. The same behavior occurs when you use the aggregate Sum() function. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.
CAUSEIf you use the Currency data type, rounding errors typically do not occur because Currency values are scaled integers rather than floating point numbers. However, the Sum() and DSum() functions store an accumulated total as a floating point number, which is limited to approximately 14 significant digits. If you require all 19 digits of precision (15 to the left of the decimal point and 4 to the right of the decimal point), you can use a custom domain aggregate function. You should use the built-in Sum() and DSum() functions if you do not require this degree of precision.
RESOLUTION
Creating the FunctionTo create a custom domain function that sums the data in a field, follow these steps:
Using DCurSum() with CriteriaYou can use criteria with DCurSum() in the same way you use criteria with DSum(). The following example uses DCurSum() to calculate the value of the entire inventory of products whose CategoryID is 1.
MORE INFORMATION
Steps to Reproduce Behavior
REFERENCESFor more information about custom domain functions, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q103401 TITLE : ACC:How to Create Custom Domain Function Similar to DCount() ARTICLE-ID: Q146415 TITLE : ACC: Creating Functions Similar to DFirst and DLast (95/97)For more information about rounding errors, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q111781 TITLE : ACC: Rounding Errors Using Floating-Point Numbers ARTICLE-ID: Q35826 TITLE : IEEE vs. Microsoft Binary Format; Rounding Issues (Complete) |
Additional query words: prb incorrect wrong rounding rounded incorrectly
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |