View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Excel VBA Int, Cint?


"Rick Rothstein (MVP - VB)" wrote in
message ...
Just to add, calculations you might expect to result as an whole number
can result as +/- a very small decimal.


And here is a perfect example of this problem. Consider this calculation
(perform it in the Immediate window for simplicity)...

Print 12.565 * 100 + 0.5

As expected, 12.565 * 100 yields 1256.5 and, after adding 0.5 to it, the
expected result of 1257 is printed out. However, slap an Int function call
around it...

Print Int(12.565 * 100 + 0.5)

and, lo-and-behold, it only prints out 1256.

<snip
Isn't floating point
arithmetic fun?<g


Another one - not unreasonable to assume if you add 0.1 ten times you'll get
1, afraid not, only 'almost' one which is hopefully near enough !

For i = 1 To 10
d = d + 0.1
Next
Debug.Print d = Int(d), (1 - d) * 1E+12!

Regards,
Peter T