[CODE]
public static class SizeUnit
{
public static string FileSizeToString(long size)
{
double FileSize = size;
string[] format = new string[] { "{0} bytes", "{0:0.00} KB", "{0:0.00} MB", "{0:0.00} GB", "{0:0.00} TB" };
int i = 0;
while (i < format.Length && FileSize >= 1024)
{
FileSize = (int)(100 * FileSize / 1024) / 100.0;
i++;
}
return string.Format(format[i], FileSize);
}
}
[/CODE]
The problem is I want it to display the size in this format with max 3 numbers!
3.90 MB | 322 KB | 4.33 KB | 300 Bytes | 0 Bytes | 3 MB | 12.5 MB | 300 MB | 32.5 KB | 700 Bytes
I use this code to display the result:
[CODE]
SizeUnit.FileSizeToString(fileInfo.Length)
[/CODE]
Thanks...

VulpesRank #55 · 29.2K reputationPosted Mar 8, 2012, 9:07 AM EST
Anyway, the following now seems to be working fine:
VulpesRank #55 · 29.2K reputationPosted Mar 8, 2012, 12:49 AM EST
Emre Ozpalamutcu39 reputationPosted Mar 8, 2012, 8:26 AM EST
Emre Ozpalamutcu39 reputationPosted Mar 8, 2012, 9:22 AM EST
Emre Ozpalamutcu39 reputationPosted Mar 8, 2012, 4:17 PM EST
Thanks.
VulpesRank #55 · 29.2K reputationPosted Mar 8, 2012, 11:32 PM EST
There's an example here on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemsorter.aspx
Emre Ozpalamutcu39 reputationPosted Mar 9, 2012, 1:45 PM EST