Tuesday, February 17, 2009
Visaul Basic .Net Show RoundUp, RoundMe
Version Compatibility : Microsoft Visual Studio 2005 Or Microsoft Visual Basic 6.0
More information : Function RoundUp and RoundMe for up decimal and not up decimal. Suppot VB 6.0, VB.Net 2005. and two function name support business software Example . Purchase Order, General Ledger, Order Entry and Other
Source Code :
Public Function RoundUp(ByVal pNumber As Double, ByVal pDigit As Integer) As Double
Dim mPlus As Double = 0.0, mDivide As Double = 0.0, mresult As Double = 0.0
Dim mText As String = ""
'-- if you make comment pDigit = 0 then decimal 0.1 to 0.9 will up to 1 alway.
'-- if you do not make comment pDigit = 0 then RoundUp return Integer decimal do not up.
'pDigit = 0
mDivide = 10 ^ pDigit
If pNumber <>
mPlus = -0.9 / mDivide '-- all up Decimal
Else
mPlus = 0.9 / mDivide '-- all up Decimal
End If
mresult = (pNumber + mPlus) * mDivide
mText = Trim(Str(mresult))
If InStr(mText, ".") > 0 Then
mText = Mid(mText, 1, InStr(mText, ".") - 1)
End If
mresult = Val(mText)
Return mresult / mDivide
End Function
Public Function RoundMe(ByVal pNumber As Double, ByVal pDigit As Integer) As Double
Dim mPlus As Double = 0.0, mDivide As Double = 0.0, mresult As Double = 0.0
Dim mText As String = ""
mDivide = 10 ^ pDigit
If pNumber <>
mPlus = -0.5 / mDivide '--- decimal up for over 0.5
Else
mPlus = 0.5 / mDivide '--- decimal up for over 0.5
End If
mresult = (pNumber + mPlus) * mDivide
mText = Trim(Str(mresult))
If InStr(mText, ".") > 0 Then
mText = Mid(mText, 1, InStr(mText, ".") - 1)
End If
mresult = Val(mText)
Return mresult / mDivide
End Function
For Example use:
Call RoundUp(100.055,2) '-- Return = 100.06 ' if you make comment pDigit = 0.
Call RoundUp(100.055,2) '-- Return = 100 ' if you do not comment pDigit = 0
Call RoundMe(100.055,2) '-- Return = 100.06 ' use function name RoundMe. it same Round on VB6 Or VB.Net.
Subscribe to:
Post Comments (Atom)
0 Comment:
Post a Comment