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
3
Medium Priority
?
188 Views
Last Modified: 2010-04-30
Example: round(10.5,0) gives as result 10. This is not a commercially correct rounding. The result has to be 11.
Solution ?????
0
Comment
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
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
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

by:deighton
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

by:pce
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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

660 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