pce
asked on
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 ?????
Solution ?????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
rounded = Int(x * 10 ^ places + 0.5) / 10 ^ places
End Function