Wednesday, October 20, 2010

Round Up Values in vb.net

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim j As Double
        Dim res As Double
        Dim st() As String
        Dim st1() As Char
        Dim count As Integer
        Dim str As String

        j = 4.5
        'MsgBox(Math.Round(j))
        str = j.ToString
        If str.Contains(".") Then
            '   MsgBox("y")
            st = str.Split(".")
            For count = 0 To st.Length - 1

            Next
            Dim temp As Integer
            st1 = st(1).ToCharArray
            temp = CInt(st(0))
            If temp Mod 2 = 0 And st(1) = "5" Then
                i = CInt(j)
                i = i + 1
                'ElseIf temp Mod 2 = 0 And st1(0) = "4" And st1(1) = "9" Then
                '    i = CInt(j)
                '    i = i + 1

            Else
                i = Math.Round(j)
            End If
        Else
            ' MsgBox("n")
            i = Math.Round(j)
        End If

      

    
        MsgBox(i.ToString)


    End Sub

No comments:

Post a Comment