VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access

by Cyrus Lacaba aka Biohazard of Las Pi?as (6 Submissions)
Category: Math/Dates
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 17th July 2009
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



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


Download this snippet    Add to My Saved Code

Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access Comments

No comments have been posted about Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access. Why not be the first to post a comment about Structured Rounding of Numbers equivalent to Round Function of VB6. Mostly used in Microsoft Access.

Post your comment

Subject:
Message:
0/1000 characters