Sprache: C#
Beispiel:
[code]
var f = SizeFormatter.Format(bytelänge, anzahlKommaStellen);
[/code]
public class SizeFormatter
{
public static string Format(double len, int decimals)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
int order = 0;
while (len >= 1024 && order + 1 < sizes.Length)
{
order++;
len = len / 1024;
}
return String.Format("{0:0." + new string('#', decimals) + "} {1}", len, sizes[order]);
}
public class SizeFormatter
{
public static string Format(double len, int decimals)
{
string[] sizes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
int order = 0;
while (len >= 1024 && order + 1 < sizes.Length)
{
order++;
len = len / 1024;
}
return String.Format("{0:0." + new string('#', decimals) + "} {1}", len, sizes[order]);
}
Alte URL:
/snippet/byte-in-groessere-einheiten-umrechnen/5951
Statt der places-Methode kannst du direkt den Konstruktor des String-Typs nutzen:
new string(‚#‘, pl)