A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Round 4 decimals up



 
 
Thread Tools Display Modes
  #1  
Old February 19th, 2007, 05:44 PM posted to microsoft.public.access.queries
Pilgrim
external usenet poster
 
Posts: 22
Default Round 4 decimals up

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
  #2  
Old February 19th, 2007, 06:35 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Round 4 decimals up

pilgrim wrote:

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.

--
Marsh
MVP [MS Access]
  #3  
Old February 19th, 2007, 07:02 PM posted to microsoft.public.access.queries
Jeff Boyce
external usenet poster
 
Posts: 1,555
Default Round 4 decimals up

Ed

Do you mean you want to STORE no more than two decimal places, or that you
want to SEE no more than two?

You could set the Decimal Places property to 2, even though more were
stored...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP
http://mvp.support.microsoft.com/

Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/

"pilgrim" wrote in message
...
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


  #4  
Old February 19th, 2007, 07:11 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Round 4 decimals up

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
..

"Marshall Barton" wrote in message
...
pilgrim wrote:

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.

--
Marsh
MVP [MS Access]



  #5  
Old February 20th, 2007, 09:38 AM posted to microsoft.public.access.queries
Jamie Collins
external usenet poster
 
Posts: 1,705
Default Round 4 decimals up

On Feb 19, 7:02 pm, "Jeff Boyce" -
DISCARD_HYPHEN_TO_END wrote:
Do you mean you want to STORE no more than twodecimalplaces, or that you
want to SEE no more than two?

You could set theDecimalPlaces property to 2, even though more were
stored...


The OP could use the DECIMAL type with the Scale property set to 2 to
ensure no more than 2 decimal places are stored but in practice it is
better to store an extra decimal place to make custom rounding
possible e.g. the OP's use of the ROUND() function suggests banker's
rounding is desired whereas a DECIMAL(n, 2) column will exhibit
symmetric truncation.

Jamie.

--


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:05 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.