• Status: Solved
• Priority: Medium
• Security: Public
• Views: 195

# ROUND function in VB

Example: round(10.5,0) gives as result 10. This is not a commercially correct rounding. The result has to be 11.
Solution ?????
0
pce
• 2
1 Solution

Commented:
use

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

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

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

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

End Function

0

Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.