Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding Number in a Query or Module

Using Functions in Queries

Rounding Number in a Query or Module

by  PaulBricker  Posted    (Edited  )
Rounding values can be a daunting task. If you have Access 2000 or newer, you have the Round Function you can use for many of your calculations. If you are using Access 97 or have calculations that don't fit in the Round Function format you can try one of these to accomplish what you need. Edited 1/11/07. to adjust for floating point issues with VB6.3
Place them in a new column in your query and replace myField with the name of your Numeric Field.

To round to 1 decimal place
myVal:Int(CDec((myField + 0.05) * 100)) / 100
123.45 returns 123.5
123.44 returns 123.4

To round to 2 decimal places
myVal:Int(CDec(myField+.005)*100)/100
123.456 returns 123.46
123.454 returns 123.45

To round to the nearest ONE digit
myVal:Int(myField + .5)
123.55 returns 124
123.45 returns 123

To round to the nearest TEN digit
myVal:Int(((Int(myField) / 100) + 0.05) * 10) * 10
128.45 returns 130
123.45 returns 120

To round to the HIGHER TEN digit
myVal:Int((((myField + 0.999) / 100) + 0.09) * 10) * 10
1.01 returns 10
10 returns 10
10.01 returns 20

The alias myVal can be replaced by any text value you want for a field name.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top