Round 4 decimals up

P

pilgrim

Hello, Using MS 2002. I know this is spelled out below but - need a liitle
help. I have records that have a cost field out to 4 decimals (12.034). I
would like to set up an update qry to round up to the nearest dollar & cents
$12.04. Any help or simple rond function to do this?
Thanks, Ed
 
M

Marshall Barton

pilgrim said:
Hello, Using MS 2002. I know this is spelled out below but - need a liitle
help. I have records that have a cost field out to 4 decimals (12.034). I
would like to set up an update qry to round up to the nearest dollar & cents
$12.04. Any help or simple rond function to do this?


UPDATE table SET Cost = Round(Cost, 2)

Always make a backup of the table before doing this kind of
global update.
 
J

John Spencer

SInce you want to round up, I would try the following.

Public Function fRoundUp (dblNumber As Double, _
Optional intPlaces As Integer) As Double
fRoundUp= -Int(-dblNumber * 10 ^ intPlaces) / 10 ^ intPlaces
End Function

This works with positive numbers. Also it will error with non-numeric
values (null, strings that can't be interpreted as a date) Also, since you
are working with doubles (floating point) the rounding can get a little
strange if you round up to more digits then you pass in.
For example
froundup (2.0211,6) --> 2.021101

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Top