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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression to round up or down X number of decimal places

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,052
US
In a MS Access select query, I need an expression to round up or down to either 0, 1 or 2 decimal places, which is being supplied via a parameter.

Maybe even a user defined function would work here, but I am open. Any ideas on how to do this?

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Try something like this:


FormatNumber(yourvariable,2) for 2 decimal places and so on..

VJ
 
Amorous,

Your answer is a simple round and does not address the "round up" and "round down" part of my question.

For example if the parameter for rounding method is "round down", then I need to express the field value of 99.999 as 99. If the parameter is set yo "round up" and the field value is 99.001, I need this expressed as 100.

Any ideas?

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Sorry for not reading the post properly.

For round up you may want to try the ceiling function

CEILING returns the next highest integer >= the number

CEILING(yourvariable)

Also try the Round() function.

VJ
 
CEILING() is not available as an expression, this must be a VB/VBA thing. How do I get this to work?

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
I am writing some code in Crystal Reports and I need to round up or down - Crystal Reports rounds only up. For example if I have a number 2.05, if I delete the 5, I need to retain 2.0. If I use Round() it will make it 2.1. This is NOT what I want. I have no problme with rounding when the digit I am deleting is either less than 5 or greater than 5. It is only when I drop a 5 that I have to follow special requirements, i.e. the preceding number should be rounded off to the nearest even number. That'w why in teh above example, the "0" stays as "0". 2.15 would become 2.2, 2.25 would become 2.2, 2.35 would become 2.4 and so on.

Any ideas/leads?

Thanks.
 

OneDecNumber=Int(LongNumber*10)/10

LongNumber=2.25
?OneDecNumber=2.2

LongNumber=2.254
?OneDecNumber=2.2

LongNumber=2.233
?OneDecNumber=2.2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top