Page 1 of 1

Problem with Vb dividing

Posted: Sat Jan 14, 2012 9:03 pm
by patsquare
Hi im making a convertor and i need help with dividing when i do ex."label1.text/1024" the answer comes up something like 1.79696973E+25 how can i get rid of that e+25 and making it display as a normal number? and round it to 10 decimal places.

Image
Image
Image

A bit of the code:
Code: Select all
 If ComboBox1.Text = "Bits" Then
            Label9.Text = TextBox1.Text
            Label10.Text = Label9.Text / 8
            Label11.Text = Label10.Text / 1024
            Label12.Text = Label11.Text / 1024
            Label13.Text = Label12.Text / 1024
            Label14.Text = Label13.Text / 1024
            Label15.Text = Label14.Text / 1024
            Label16.Text = Label15.Text / 1024
            Label18.Text = Label16.Text / 1024
            Label21.Text = Label18.Text / 1024

        ElseIf ComboBox1.Text = "Bytes" Then
            Label9.Text = Label10.Text * 8
            Label10.Text = TextBox1.Text
            Label11.Text = Label10.Text / 1024
            Label12.Text = Label11.Text / 1024
            Label13.Text = Label12.Text / 1024
            Label14.Text = Label13.Text / 1024
            Label15.Text = Label14.Text / 1024
            Label16.Text = Label15.Text / 1024
            Label18.Text = Label16.Text / 1024
            Label21.Text = Label18.Text / 1024

        ElseIf ComboBox1.Text = "Kilobytes" Then
            Label9.Text = Label10.Text * 8
            Label10.Text = Label11.Text * 1024
            Label11.Text = TextBox1.Text
            Label12.Text = Label11.Text / 1024
            Label13.Text = Label12.Text / 1024
            Label14.Text = Label13.Text / 1024
            Label15.Text = Label14.Text / 1024
            Label16.Text = Label15.Text / 1024
            Label18.Text = Label16.Text / 1024
            Label21.Text = Label18.Text / 1024

        ElseIf ComboBox1.Text = "Megabytes" Then
            Label9.Text = Label10.Text * 8
            Label10.Text = Label11.Text * 1024
            Label11.Text = Label12.Text * 1024
            Label12.Text = TextBox1.Text
            Label13.Text = Label12.Text / 1024
            Label14.Text = Label13.Text / 1024
            Label15.Text = Label14.Text / 1024
            Label16.Text = Label15.Text / 1024
            Label18.Text = Label16.Text / 1024
            Label21.Text = Label18.Text / 1024

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 9:43 pm
by mandai
When you use the divide operator it will return a double (floating point) number.
You can declare the result as an integer type to round up the floating point.

For example:
Code: Select all
        Dim int1 As Integer = Label10.Text / 1024
        Label11.Text = int1.ToString()

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:02 pm
by patsquare
doesn't work gives an ans of 0

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:03 pm
by Bogoh67
or mandai he could just use Math.round like this
Code: Select all
   Label2.Text = Math.Round(Label1.Text / 1024, a) 'Where "a" is put how many digits you want 
right?

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:10 pm
by patsquare
used it like this :
Code: Select all
 ElseIf ComboBox1.Text = "Yottabytes" Then
            Label9.Text = Label10.Text * 8
            Label10.Text = Math.Round(Label11.Text * 1024, 4)
            Label11.Text = Math.Round(Label12.Text * 1024, 4)
            Label12.Text = Math.Round(Label13.Text * 1024, 4)
            Label13.Text = Math.Round(Label14.Text * 1024, 4)
            Label14.Text = Math.Round(Label15.Text * 1024, 4)
            Label15.Text = Math.Round(Label16.Text * 1024, 4)
            Label16.Text = Math.Round(Label18.Text * 1024, 4)
            Label18.Text = Math.Round(Label21.Text * 1024, 4)
            Label21.Text = TextBox1.Text
and doesn't work :/
result : Image

with division it works

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:18 pm
by Bogoh67
strange i typed
Code: Select all
   Label1.Text = Math.Round(Label2.Text * 9216, 5)
with 1.2089729872943526873457824356283405742435892345 being label2 and label1 being 0 so i guess try setting the label to 0 then try rounding

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:26 pm
by patsquare
That's because I've got realy large numbers not decimals like 1,000,000,000,000,000,000,000 for eg 1yettabyte = 1,208,925,819,614,629,174,706,176 bytes or 2^80 bytes i need to get the standard form i think 2^80 = 1.20892582 × 10^24 anyway to do this on vb?

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:33 pm
by MrAksel
I think you can use the long data type to display bigger numbers. Or you can write your own ToString function. Search that on google.

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:33 pm
by Axel
I think it will be very hard to handle such large numbers

Re: Problem with Vb dividing

Posted: Sat Jan 14, 2012 10:45 pm
by patsquare
Thank you i used ulong and it worked great :)