Improve nice_size() a bit

This commit is contained in:
Vedran Ljubovic 2007-07-18 18:08:18 +00:00
parent d4d31b8310
commit 2d24cd2dc2

View File

@ -206,19 +206,23 @@ char* wstrim(const char *string)
const char* nice_size(double size) {
static char buffer[256];
if (size<1024) {
snprintf(buffer,255,"%d B",(int)size);
snprintf(buffer,255,"%.0f B",size);
} else if (size<1024*10) {
snprintf(buffer,255,"%.1f kB",(float)size/1024);
snprintf(buffer,255,"%.2f kB",size/1024);
} else if (size<1024*100) {
snprintf(buffer,255,"%.1f kB",size/1024);
} else if (size<1024*1024) {
snprintf(buffer,255,"%d kB",(int)size/1024);
snprintf(buffer,255,"%.0f kB",size/1024);
} else if (size<1024*1024*10) {
snprintf(buffer,255,"%.1f MB",(float)size/(1024*1024));
snprintf(buffer,255,"%.2f MB",size/(1024*1024));
} else if (size<1024*1024*10) {
snprintf(buffer,255,"%.1f MB",size/(1024*1024));
} else if (size<1024*1024*1024) {
snprintf(buffer,255,"%d MB",(int)size/(1024*1024));
snprintf(buffer,255,"%.0f MB",size/(1024*1024));
} else if (size<1024*1024*1024*10) {
snprintf(buffer,255,"%.1f GB",(float)size/(1024*1024*1024));
snprintf(buffer,255,"%.2f GB",size/(1024*1024*1024));
} else {
snprintf(buffer,255,"%d GB",(int)size/(1024*1024*1024));
snprintf(buffer,255,"%.1f GB",size/(1024*1024*1024));
}
return (const char*) buffer;
}