PRB: Format Function May Return Incorrect ValuesLast reviewed: October 22, 1997Article ID: Q174155 |
The information in this article applies to:
SYMPTOMSDecimal values rounded by the Format function may be incorrect. For a specific decimal number, the rounded value returned by the Format function may differ for different data types and between different versions of Microsoft Visual Basic.
CAUSEWhen a variable is passed into the Format function, an algorithm is used to determine the most appropriate numeric data-type to convert the value to, and how to format it. This algorithm may not evaluate certain decimal values as expected.
RESOLUTIONTo avoid these unexpected conversions, explicitly convert the value to the desired data type before using the Format function. For instance, use the CCur function to convert the decimal value to a currency data-type that maintains more accuracy in rounding.
MORE INFORMATIONDecimal values stored in single and double data-types are binary representations of the number. Certain decimal values cannot be exactly represented in binary and are approximately represented. When evaluated by the Format function, these values may not be rounded as expected. There are two methods recommended to minimize these errors:
Steps to Reproduce Behavior
REFERENCESFor additional information, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q42980 TITLE : (Complete) Tutorial to Understand IEEE Floating-Point Errors ARTICLE-ID: Q69333 TITLE : HOWTO: Work Around Floating-Point Accuracy/Comparison Problems |
Additional query words: Precision
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |