Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all , i'm building a downloader using vb.net 2008 , all things is working good
but what my problem is when i try to show the file size in MB i can't show the number of digits before the dot , for example i want to show only 4 digits before the dot in the result as 3.1234 and not as 3.12345677
the code i use to convert bytes to MB in my project is as :
VB
Label1.Text = ((e.TotalBytesToReceive / 1024) / 1024) & "MB"


hope some one will help me .. thanks in advance :)
Posted
Comments
[no name] 24-Sep-14 7:30am    
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
Hamdi Choban 24-Sep-14 7:58am    
thanks very much, i opened the website and after reading it all i solved my problem :)

Try formatting the amount like this;
VB
Label1.Text = String.Format("{0:###,##0.0000}MB", (e.TotalBytesToReceive / 1024.0) / 1024.0))


Hope this helps,
Fredrik
 
Share this answer
 
v4
Comments
Hamdi Choban 24-Sep-14 7:39am    
i tried it but it did not work and gave me "Exception has been thrown by the target of an invocation."

thanks for trying help me .
Fredrik Bornander 24-Sep-14 8:03am    
Sorry about that, I forgot the initial 0: in the format string.
Hamdi Choban 24-Sep-14 8:07am    
its ok :) thanks for helping bro
thanks for all for trying to help me .. the solution code :
VB
Label1.Text = String.Format("{0}", (((e.TotalBytesToReceive / 1024) / 1024)).ToString("F04")) & "MB"


:) thanks @wes Aday and thanks @Fredrik Bornander for trying helping me :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900