| Round Up and Down |
|
|
|
| Tutorials | |||
| Written by Administrator | |||
|
Below there are two functions to round down double values in Visual Basic. For instance roundDown(4,567) will result in 4.
"Code" '*************************************
'**** 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
|



