|
using System;
using System.Collections.Generic;
using System.Text;
namespace FileFind
{
class NumericScaling
{
public static string DisplayScaledNamesBytes(long i)
{ //returns 9.99 KB (99,999)
string result = i.ToString("N0");
string[] names = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB" };
long incr = 1024;
for (int j = 0; j < names.Length; ++j)
{
if (i < incr)
{
double res = (double)((double)i / ((double)incr / 1024D));
result = res.ToString("N") + " " + names[j]
+ " (" + i.ToString("N0") + ")";
break;
}
else
incr *= 1024L;
}
return result;
} //ends public static string DisplayBytesNames(long i)
public static string DisplayScaledNames(long i)
{ //returns 9.99 KB
string result = i.ToString("N0");
string[] names = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB" };
long incr = 1024;
for (int j = 0; j < names.Length; ++j)
{
if (i < incr)
{
double res = (double)((double)i / ((double)incr / 1024D));
result = res.ToString("N") + " " + names[j];
break;
}
else
incr *= 1024L;
}
return result;
} //ends public static string DisplayBytesNames(long i)
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.