Solved

Looking for a faster solution to a rounding function in access query.

Posted on 2012-03-09
8
264 Views
Last Modified: 2012-08-13
I am looking to see if there is a faster alternative to the Rounding function we picked up from a previous question posted. Currently using a function called Round16. It looks like;

Public Function Round16(ByVal v As Double, Optional ByVal lngDecimals As Long = 0) As Double
' by Filipe Lage, fclage-NO~SPAM@kiss-ezlink.com, 20050322
  Round16 = CDbl(Format$(v * 10 ^ lngDecimals, "0")) / 10 ^ lngDecimals
End Function


This is working properly but it is slow. Anyone know of a faster alternative to this? The built in Round() function is not rounding properly for some reason.

Thanks for the help!
0
Comment
Question by:SeyerIT
8 Comments
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 200 total points
ID: 37702851
Rounding in Access is more complicated than you might think.  See Access Archon #94 (a guest article by Geoff Shepherd) for lots of info on rounding.

http://www.helenfeddema.com/Files/accarch94.zip
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 37703074
dont use function, use it in sql... does it make any difference?

select Round16(v, 2) as rounded_value from mytable
>>>
select CDbl(Format$(v * 10 ^ 2, "0")) / 10 ^ 2 as rounded_value from mytable
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 200 total points
ID: 37703215
Yes, use the Round15 from this link which also performs a perfect 4/5 rounding:

http://www.xbeat.net/vbspeed/c_Round.htm

/gustav
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 100 total points
ID: 37708381
@gustav

Why not use the Round17 code?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37708563
Right, sorry, I didn't notice but did a copy and past from an old post.

/gustav
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37709235
btw...are you the gustav that contributed Round12 & Round15?  If so, thank you for your participation in that wonderful little repository of VB goodness/speediness.
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37709321
Thanks all for your help! Sorry I'm just now getting back to this. Those seem to work better.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37709865
You are welcome!

And yes, that Gustav is me.

/gustav
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now