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!

rounding problem

Status
Not open for further replies.

MushMouse

Programmer
Mar 29, 2004
65
US
I have a field called MinGauge in a table.
fieldsize: single
decimal places: auto

In a query, I have the following code:
MinGauge
Test: IIf([MinGauge]>0,[MinGauge],0)

When I print run the query , here's a sample of results:
MinGauge Test
0.015 0.0149999996647239
0.1 0.100000001490116

Can anyone tell me why this is happening & how I can make the value in Test = to MinGauge when MinGauge > 0?

Thanks!

 
You may try this:
Test: CDec(IIf([MinGauge]>0,[MinGauge],0))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I got just tried it.
I keep getting the error message "The expression you entered has a function containing the wrong number of arguments".
I can't imagine why CDec isn't working. I even tried "CDec(MinGauge) & got the same error message.
So I tried replacing CDec with CSng.
No error message, but rounding problem still appears.
I did a search in my project to see if maybe I had accidentally used CDec as a public variable. I didn't.

I read someplace that access has a rounding problem which can be alleviated by using the Round function. I've incorporated it into the code & am getting the desired results, but I still find it disturbing that the actual values are not accurate and that I have to choose a value to round by.....

The working code is below:
Test: Round((IIf([MinGauge]>0,[MinGauge],0))+0.000001),5)
 
If you deal with EXACT values then don't use Single nor Double.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Decimal or Currency.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top