Thursday, November 17, 2011

Roundn Function

The standard ROUND function allows you to round to a particular decimal point.  Roundn is a function I use all the time that allows you to round to any number.  Below is the code:

Public Function roundn(Number As Double, RoundTo As Double) As Double
    roundn = Round(Number / RoundTo, 0) * RoundTo
End Function

In Excel, this function could be used to calculate the following:

=roundn(123456,500) = 123,500
=roundn(1234.5678,.0005) = 1,234.55
=roundn(1000/3,0.25) = 333.25

No comments:

Post a Comment