22 | 02 | 2017

Round Up and Down

Below there are two functions to round down double values in Visual Basic. For instance roundDown(4,567) will result in 4.

'*************************************
'**** Code from VisibleVisual.com ****
'*************************************

Public Function roundDown(value2round As Double) As Double
On Error GoTo Errorhandler
Dim myDec As Long

myDec = InStr(1, CStr(value2round), ".", vbTextCompare)
If myDec > 0 Then
roundDown = CDbl(Left(CStr(value2round), myDec))
Else
roundDown = value2round
End If
Exit Function
Errorhandler:
MsgBox Err.Description, vbInformation, "Round Down"
End Function





Public Function roundUp(value2round As Double) As Double
On Error GoTo Errorhandler
Dim myDec As Long

myDec = InStr(1, CStr(value2round), ".", vbTextCompare)
If myDec > 0 Then
roundUp = CDbl(Left(CStr(value2round), myDec)) + 1
Else
roundUp = value2round
End If
Exit Function
Errorhandler:
MsgBox Err.Description, vbInformation, "Round Up"
End Function
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2174906
Latest Articles