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

Round function produces wrong answers in Access 1

Status
Not open for further replies.

ashfaque1

Programmer
Jul 12, 2003
3
QA
I have used round function in a DB. but it gives results as follows :

function returns
round(1.5) 2
round(2.5) 2
round(3.5) 4
round(12.5) 12
round(13.5) 14
.
.
.
.

I could not understand where the figure contains value 2 the .5 is not rounded to next digit but a previous one.

Could anybody suggest me the solution of this problem/bug.

 
Round will use standard rounding practice and will therefore round .5 to the nearese Even number so 2.5 goes to 2 but 3.5 goes to 4
 
A workaround is to use the Format function:

Format (2.5, "#")

returns 3
but format (2.49, "#")
returns 2

John
 
Mr.John, the format functions does not work as you specified.
I am developing a Payroll Software, and I am using MS Excel to make the time sheet of an employee. My calculation in excel does not match to the calculation in Access. Because (as per above) access round function is rounding to the nearest even number.

 
Ashfaque1, What function are you using in Excel, The round function uses the same standard rounding as Access (i.e. nearest even number) but there are roundup and rounddown funstions, are you using one of these instead?
 
No I'm lying it doesn't, ignore that last post.......
 
There are two methods of rounding:

The european method: .5 or more is rounded up

The american method .5 is rounded towards the nearest even number.

It seems access uses the american method, or it might be a local setting, I don't know. However, the formula

Code:
Int(x+0.5)

rounds x according to the european method.

Best regards
 
Thanks DonQuichote, that's just what I was looking for. Watch out for those windmills.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top