Home General VB/VBA Round Up and Down
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Round Up and Down PDF Print E-mail
User Rating: / 0
PoorBest 
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"
View source
'*************************************
 
 
 
	'**** 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

 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade