Last active
January 29, 2016 15:14
-
-
Save xentec/d02888591d4b7d21fa01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string humanByte(byte decimals = 2)(double bytes) | |
{ | |
import std.string; | |
enum suffix = [ "", "K", "M", "G", "T", "P", "E"]; | |
byte i; | |
while(bytes > 1024.0) { | |
bytes /= 1024.0; | |
i++; | |
} | |
return format("%."~ decimals.to!string ~"f %siB", bytes, suffix[i]); | |
} | |
string humanByte(double bytes, byte decimals = 2) | |
{ | |
import std.string; | |
enum suffix = [ "", "K", "M", "G", "T", "P", "E"]; | |
byte i; | |
while(bytes > 1024.0) { | |
bytes /= 1024.0; | |
i++; | |
} | |
return format(format("%%.%df %siB", decimals, suffix[i]), bytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment