Results 1 to 3 of 3

Thread: [RESOLVED] Round number to 1 decimal place

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    20

    Resolved [RESOLVED] Round number to 1 decimal place

    Hi! When I want to reduce mbytesIn and totalmBytes to one decimal place with Math.Round(), it doesn't change anything. It works for speed meter and percentage well so I don't know what's bad...
    Thanks for any help!

    Code:
     Private Sub download_change(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
            Dim mbytesIn As Double = Double.Parse(e.BytesReceived.ToString()) / 1000000
            Dim totalmBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString()) / 1000000
            Dim percentage As Double = mbytesIn / totalmBytes * 100
            pb_load.Value = Int32.Parse(Math.Truncate(percentage).ToString())
            percentage = Math.Round(percentage, 0)
            la_perc.Text = percentage & " %"
            Dim unita As String
            If totalmBytes < 1 Then
                totalmBytes = totalmBytes * 1000
                unita = " kB"
                If totalmBytes < 1 Then
                    totalmBytes = totalmBytes * 1000
                    unita = " B"
                End If
            ElseIf totalmBytes > 1000 Then
                totalmBytes = totalmBytes / 1000
                unita = " GB"
            Else
                unita = " MB"
            End If
            Dim unitb As String
            If mbytesIn < 1 Then
                mbytesIn = mbytesIn * 1000
                unitb = " kB"
                If mbytesIn < 1 Then
                    mbytesIn = mbytesIn * 1000
                    unitb = " B"
                End If
            ElseIf mbytesIn > 1000 Then
                mbytesIn = mbytesIn / 1000
                unitb = " GB"
            Else
                unitb = " MB"
            End If
            Math.Round(mbytesIn, 1)
            Math.Round(totalmBytes, 1)
            la_size.Text = mbytesIn & unitb & " / " & totalmBytes & unita
            Dim speed As Double = e.BytesReceived / SW.ElapsedMilliseconds / 1000
            Dim unit As String
            If speed < 1 Then
                unit = " kB/s"
                speed = speed * 1000
                If speed < 1 Then
                    unit = " B/s"
                    speed = speed * 1000
                End If
            Else
                unit = " MB/s"
            End If
            speed = Math.Round(speed, 1)
            la_speed.Text = "Download speed: " & speed & unit
        End Sub

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Round number to 1 decimal place

    It works for speed and percentage because you're doing this:

    Code:
    value = Math.Round(value,n)
    With mBytesIn and totalmBytes you're just doing:

    Code:
    Math.Round(value,n)
    So do this:

    Code:
        mbytesIn = Math.Round(mbytesIn, 1)
        totalmBytes = Math.Round(totalmBytes, 1)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2015
    Posts
    20

    Re: Round number to 1 decimal place

    Oh I overlooked it. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width