ID: Q111781
The information in this article applies to:
Novice: Requires knowledge of the user interface on single- user computers.
When you calculate using floating-point numbers, the result is not always what you expect. For example, if you use the CInt() (convert to integer) function in the calculation
CInt(3.555 * 100)
you receive 356 as the result, as you expect. However, the calculation
CInt(4.555 * 100)
results in 455 instead of 456.
Errors similar to the example above occur in any programming language that uses floating-point numbers. This is because decimal fractions do not always have exact binary equivalents, which can result in rounding errors.
There are several methods you can use to avoid rounding errors when you are using floating-point numbers:
CInt(4.555@ * 100)
results in a value of 456.
CInt(4.555 * 100)
the value 455.5 is temporarily stored and used in the CInt() function. If you break the calculation into the two steps
x = 4.555 * 100
CInt(x)
you avoid this internal storage and thus avoid the floating-point rounding error.
Keywords : kbprg
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Last Reviewed: November 20, 1998