A complex subject.
There are numerous ways to approach rounding: You have to take into consideration such things as Bankers Rounding, and the various default roundings applied by intrinsic
vb functions.
Here is a little code that hopefully does what you wnnt:
Code:
Private Sub Command1_Click()
Dim dblPlaces As Double
Dim dblAmount As Double
Dim dblRounded As Double
dblAmount = 34.01
' dblPlaces is the decimal place you want to round to:
' 1 = no decimal places
' 10 = 1 decimal place
' 100 = 2 decmial places... and so on
dblPlaces = 1
dblRounded = Fix(dblAmount * dblPlaces) / dblPlaces
' The following needs to be done for positive amounts, but not
' for negative amounts for true "rounding up" functionality
' so you would need to add a test for negative amounts and NOT
' do this for negatives.
dblRounded = dblRounded + (1 / dblPlaces) ' See note below
Debug.Print dblRounded
End Sub
Note the line of code that moves the value up for positive numbers. You don't do this for the negative numbers as you'll move one value unit too far. Also remember that rounding up for negative numbers moves you towards zero. If you always want to move "away" from zero, then you have to apply the ABS function to your calculations and then re-apply the sign after the rounding operation is complete.
Make sense?
Have fun...
Woody Z
http://www.learntoprogramnow.com