Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# ROUND function in VB

Posted on 1999-08-02
Medium Priority
188 Views
Example: round(10.5,0) gives as result 10. This is not a commercially correct rounding. The result has to be 11.
Solution ?????
0
Question by:pce
[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
• 2

LVL 18

Accepted Solution

deighton earned 450 total points
ID: 1528892
use

int(x + .5) to round .5 up.

They are rounding .5 to the nearest even number.
0

LVL 18

Expert Comment

ID: 1528893
Private Function rounded(x As Double, places As Integer) As Double

rounded = Int(x * 10 ^ places + 0.5) / 10 ^ places

End Function

0

Author Comment

ID: 1528894
The rounded function as you proposed works fine for our given example (13.5). However, if you try it as following :
a=rounded(13.35,1) the result is 13.3 instead of the expected 13.4.
We have changed the function :

Private Function rounded(x As Double, places As Integer) As Double
rounded = x * 10 ^ places + 0.5
rounded = Int(rounded) / 10 ^ places
End Function

0

## Featured Post

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
###### Suggested Courses
Course of the Month4 days, 10 hours left to enroll