Solved

# Rounding

Posted on 2002-07-19
260 Views
i need to be able to round down and round up (a number of course). any know how?
0
Question by:CyberAccess
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 43

Expert Comment

ID: 7164670
Use the Round() function!

Debug.Print Round(3.3)
Debug.Print Round(3.6)
Debug.Print Round(3.678,2)
0

LVL 4

Expert Comment

ID: 7164671
Sounds too easy :)
0

LVL 44

Expert Comment

ID: 7164685
be aware the the Round function uses "Banker's Rounding":

If a Value is EXACTLY .5, then if the rounding will be to the EVEN whole Number - 2.5 will ROUND Down to 2, 3.5 will ROUND Up to 4.

Arthur Wood
0

LVL 70

Expert Comment

ID: 7164686
One thing for sure, do not use the Format function to round numbers. To know more on this subject, have a look at http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20311047
0

LVL 7

Expert Comment

ID: 7164813
Be aware that the VB Round function, while more accurate, is not acceptable by the IRS and many businesses will complain about it.  Here's the function I use... it's crude but effective:

Public Function fc_spRound(ac_Amount As Currency, al_Places As ppRound) As Currency
If ac_Amount < 0 Then
Select Case al_Places

Case ppOneCent
fc_spRound = Fix((ac_Amount - 0.005) * 100) / 100

Case ppFiveCents
fc_spRound = Fix((ac_Amount - 0.025) * 20) / 20

Case ppDollar
fc_spRound = Fix(ac_Amount - 0.5)

Case ppTruncateToCents
fc_spRound = Fix(ac_Amount * 100) / 100

Case ppTruncateToDollars
fc_spRound = Fix(ac_Amount)

End Select

Else
Select Case al_Places

Case ppOneCent
fc_spRound = Fix((ac_Amount + 0.005) * 100) / 100

Case ppFiveCents
fc_spRound = Fix((ac_Amount + 0.025) * 20) / 20

Case ppDollar
fc_spRound = Fix(ac_Amount + 0.5)

Case ppTruncateToCents
fc_spRound = Fix(ac_Amount * 100) / 100

Case ppTruncateToDollars
fc_spRound = Fix(ac_Amount)

End Select
End If
End Function
0

LVL 7

Expert Comment

ID: 7164826
Here is a link to more than you ever wanted to know about rounding in VB:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q196652&SD=MSKB&
0

LVL 2

Accepted Solution

mbenassor earned 20 total points
ID: 7169279
I also crossed this problem, you can use my function :

x : is the number you want to apply round
n : number of digits to keep

Private Function NewRound(x As Double, n As Integer) As Double
Dim factor As Double, y As Double

factor = 10 ^ n
y = x * factor + Sgn(x) * 0.5
NewRound = Fix(y) / factor
End Function
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

VBS file using code from 2nd file (txt or vbs) 4 55
Microsoft Access combo box help 2 57
Visual Studio 2005 text editor 10 55
Fastest way to find and count same items VB6 16 62
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
###### Suggested Courses
Course of the Month5 days, 7 hours left to enroll