DerFarm is right...an integer is an INTEGER!
Try this:
Code:
Dim sngAvgSetsPerDay As Single ' Forgive me...VB habits die hard :)
sngAvgSetsPerDay =(Last_Date - First_Date)/NumSets
An Integer (or a Long) is a whole number, whereas a Single (or Double) can have a decimal number value.
Hope that helps!
I misunderstood your question
I don't think your question was clear initially. I thought you wanted to know why the result was rounded to the nearest integer.
True, this is the way that VB handles it - rounding instead of truncating. Don't know why.
Rounding is more accurate
Actually, rounding is more accurate, isn't it?
If you add the results of rounded numbers, you will be closer to the actual result than if you add the result of truncated numbers.
When adding numbers less or equal to .5 away from the whole part, the methods work identically. The further away you move from .5 toward the next whole number, the less acurate truncating is.
i.e:
Code:
' Actual numbers:
' 1.1 + 1.3 + 1.5 + 1.7 + 1.9 = 7.5
'
' Truncated numbers:
' 1 + 1 + 1 + 1 + 1 = 5 (difference = 2.5)
'
' Rounded numbers:
' 1 + 1 + 1 + 2 + 2 = 7 (difference = .5)
'
' ***** ANOTHER EXAMPLE *****
'
' Using the same number over and over:
' 1.6 * 10 = 16
'
' Truncated version:
' 1 * 10 = 10 (difference = 6)
'
' Rounded version:
' 2 * 10 = 20 (difference = 4)
This leads me to believe that VB is a little more advanced than languages like C when it comes to converting decimals to whole numbers! :)
[Edited by seaweed on 10-03-2000 at 05:41 PM]