- Home
·
- Math/Dates
·
- Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access
Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access
Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access... Enjoy
Rate Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access
(1(1 Vote))
On Error GoTo RoundNoErr
Dim strValue$, strValue2$, intstrValuelength%, intNextValue%, strValuetoAdd$, intValLength%, ix%
strValue$ = CStr(Val(fltValue))
intValLength% = intDecimalPlaces + 2
If intDecimalPlaces = 0 Then
Dim intFixValue%
intFixValue% = Fix(Val(fltValue))
strValue2$ = Mid(strValue$, 3)
If Val(Mid(strValue2$, 1, 1)) >= 5 Then
RoundNo = intFixValue% + 1
Else
RoundNo = intFixValue%
End If
Exit Function
ElseIf (intValLength% = Len(strValue$)) Or _
(strValue$ = "0.0" Or strValue$ = "0") Or _
(intDecimalPlaces < 0) Then
strValue2$ = strValue$
GoTo ReturnTheSameValue
End If
strValue2$ = Mid(strValue$, 1, intValLength%)
intNextValue% = Val(Mid(strValue$, intValLength% + 1, 1))
If intNextValue% >= 5 Then
intstrValuelength% = Len(strValue2$)
strValuetoAdd$ = "0."
For ix = 3 To intstrValuelength%
If ix = intstrValuelength% Then Exit For
strValuetoAdd$ = strValuetoAdd$ & "0"
Next
strValuetoAdd$ = strValuetoAdd$ & "1"
RoundNo = CDbl(strValue2$) + CDbl(strValuetoAdd$)
Else
GoTo ReturnTheSameValue
End If
Exit Function
ReturnTheSameValue:
RoundNo = CDbl(strValue2$)
Exit Function
RoundNoErr:
RoundNo = 0
End Function
Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access Comments
No comments yet — be the first to post one!
Post a Comment