CDbl Function Returns Wrong Value with Currency Data TypeLast reviewed: July 29, 1997Article ID: Q123186 |
The information in this article applies to:
SYMPTOMSIn Microsoft Visual Basic, Applications Edition, the CDbl Function may return the incorrect value when you use a currency data type in the function.
CAUSEThis behavior occurs because the Cdbl function uses the incorrect conversion when you use a currency data type in the function. For example, when you run the following procedure, the value 5.54975987041018E-18 is displayed in the message box, instead of the expected value 0:
Sub Test() Dim cy As Currency, x As Double cy = 0.1 x = cy MsgBox x - CDbl(cy) End SubIn the above example, the CDbl function is used to convert the variable cy (Currency data type) to Double data type. If this occurred correctly, the result of subtracting Cdbl(cy) from x should be 0. This behavior occurs because the conversion used with Currency data type incorrectly preserves extra precision and the result is not zero.
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONYou can use the CDbl Function to convert any valid numeric or string expression to Double data type. For example, use CDbl to force double- precision arithmetic in cases where currency or integer arithmetic normally would occur. Double data type values are stored as a 64-bit (8-byte) number ranging in value from -1.79769313486232E308 to -4.94065645841247E-324 for negative values and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
REFERENCESFor more information about the CDbl Function, choose the Search button in the Visual Basic Reference, and type the following:
CDbl Keywords : kbprg Version : 1.00 Platform : WINDOWS |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |