roundup()

W

willie

the following code should work just like the roundup() funciton in excell.
Except the in the step where the clng function is use. is rounding the
number and the result is not the same as in excell. example if the number is
100.1973 the result we get bacj is 100.21. can someone help me with this

Public Function Roundup(dblNumber As Double, varRoundAmount As Double, _
Optional varUp As Variant) As Double

Dim dblTemp As Double
Dim lngTemp As Long


dblTemp = dblNumber / varRoundAmount
lngTemp = CLng(dblTemp)

If lngTemp = dblTemp Then
Roundup = dblNumber
Else
If IsMissing(varUp) Then
' round down
dblTemp = lngTemp
Else
' round up
dblTemp = lngTemp + 1
End If
Roundup = dblTemp * varRoundAmount
End If


End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Calling a function 2
Rounding help 1
roundup() function 2
Help with This Expression 2
RoundToNearest 2
Rounding Up 3
RoundUp Function not giving same answer as Excel RoundUp 2
5.5555555E02 gives wrong number 3

Top