Round number subject to it's value

S

Saintsman

On my forms, reports I would like to show calculated numbers rounded
according to their value
eg up to 10 round to 1 dec place eg 5.6
up to 100 round to nearest whole number eg 50.8 rounds to 51 (not 51.0 if
possible)
up to 1000 round to nearest 10 eg 653 rounds to 650
over 1000 round to nearest 100 eg 2175 rounds to 2200
This only needs to be done 'for show' actual calculations will be stored in
tables as calculated.
Many thanks in anticipation
 
V

vanderghast

Public Function RoundTo(x As Double) As Double

Dim s As Variant

s = CDec(Switch(x < 10, 0.1, x < 100, 1, x < 1000, 10, True, 100))
RoundTo = s * Int(CDec(0.5) + x / s)


End Function




Vanderghast, Access MVP
 

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

Top