Problem with Vb dividing

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts Page 1 of 1
Contributors
User avatar
patsquare
Just Registered
Just Registered
Posts: 9
Joined: Sun Apr 03, 2011 4:19 pm

Problem with Vb dividing
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
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Problem with Vb dividing
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()
User avatar
patsquare
Just Registered
Just Registered
Posts: 9
Joined: Sun Apr 03, 2011 4:19 pm

Re: Problem with Vb dividing
patsquare
doesn't work gives an ans of 0
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Problem with Vb dividing
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?
User avatar
patsquare
Just Registered
Just Registered
Posts: 9
Joined: Sun Apr 03, 2011 4:19 pm

Re: Problem with Vb dividing
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
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Problem with Vb dividing
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
User avatar
patsquare
Just Registered
Just Registered
Posts: 9
Joined: Sun Apr 03, 2011 4:19 pm

Re: Problem with Vb dividing
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?
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Problem with Vb dividing
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.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Problem with Vb dividing
Axel
I think it will be very hard to handle such large numbers
http://vagex.com/?ref=25000
User avatar
patsquare
Just Registered
Just Registered
Posts: 9
Joined: Sun Apr 03, 2011 4:19 pm

Re: Problem with Vb dividing
patsquare
Thank you i used ulong and it worked great :)
10 posts Page 1 of 1
Return to “Coding Help & Support”