Hi Robb and John,
Adding a fractional amount is prone to errors. Suppose your
calculation result is 5.49999999? You will get 6 as a result instead of 5.
Or if your calculation result is -5.5. You will get -5 instead of -6.
Better to use something like this:
Sgn([field]*[field1]*[field2]*[field3]) *
CInt(Abs([field]*[field1]*[field2]*[field3]/12) + 0.5)
Or more generally, for rounding to the larger absolute value when the
value is mid-way, you might write your own function:
Public Function RoundLarger(ByVal dblValue As Double, _
ByVal intDecimals As Integer) As Double
RoundLarger = Sgn(dblValue) * CInt(Abs(dblValue) * _
(10 ^ intDecimals) + 0.5) / (10 ^ intDecimals)
End Function
And then use that in place of the built-in Round() function. This
function will also allow the specification of a negative for the decimals so
you can round whole numbers to the nearest tens, hundreds, thousands, etc.
Something the built-in Round() function will not do.
? Round(5.5, 0)
6
? RoundLarger(5.5, 0)
6
? Round(6.5, 0)
6
? RoundLarger(6.5, 0)
7
? Round(-5.5, 0)
-6
? RoundLarger(-5.5, 0)
-6
? Round(-6.5, 0)
-6
? RoundLarger(-6.5, 0)
-7
? Round(123.455, 2)
123.46
? RoundLarger(123.455, 2)
123.46
? Round(123.465, 2)
123.46
? RoundLarger(123.465, 2)
123.47
? Round(555, -1)
[error 5]
? RoundLarger(555, -1)
560
? Round(565, -1)
[error 5]
? RoundLarger(565, -1)
570
Clifford Bass