Convert File Size Int to human readable format.
var size2str = function(s,d,b){var i=0,t=" KMGTPEZY";while(s>999){s/=(b?1000:1024);i++} return s.toFixed(d)+" "+(i?t[i]:"")+(b||i==0?"B":"iB")};
size2str(1025, 2)
# function(bytes_size, digits_after_dot, true_for_MB_standart)
> "1.00 KiB"
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
The "for" loop is shorter: t[undefined] is falsy, so t[i]||"" works, too (124bytes):
function(s,d,b){for(var i=0,t=" KMGTPEZY";s>999;s/=(b?1000:1024),i++);return s.toFixed(d)+" "+(t[i]||"")+(b||i==0?"B":"iB")}
Nice touch to give the user the choice between mega- and mebibytes.