Round number subject to it's value

  • Thread starter Thread starter Saintsman
  • Start date Start date
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
 
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
 
Back
Top