[PC-BSD Commits] r6574 - pcbsd/trunk/libpcbsd
svn at pcbsd.org
svn at pcbsd.org
Tue Apr 20 09:04:53 PDT 2010
Author: kris
Date: 2010-04-20 09:04:53 -0700 (Tue, 20 Apr 2010)
New Revision: 6574
Modified:
pcbsd/trunk/libpcbsd/utils.cpp
Log:
Fixed human readable output for memory sizes
Modified: pcbsd/trunk/libpcbsd/utils.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/utils.cpp 2010-04-20 14:53:01 UTC (rev 6573)
+++ pcbsd/trunk/libpcbsd/utils.cpp 2010-04-20 16:04:53 UTC (rev 6574)
@@ -50,15 +50,27 @@
{
QString suffix[] = {"B", "KB", "MB", "GB", "TB"};
long long remainder;
+ long long div = 1024;
int i = 0;
- while((bytes >= 1000) && (i < 4))
+ while ( bytes > 1024 && (i < 4) )
{
- remainder = bytes % 1024;
- bytes = bytes / 1024;
- i++;
+ remainder = bytes % 1024;
+ bytes = bytes / 1024;
+ i++;
}
- QString pointval = QString::number(remainder);
- pointval.truncate(2);
- QString result = QString::number(bytes) + "." + pointval;
+
+ QString pointval;
+ if ( i == 3 ) {
+ pointval = QString::number(remainder);
+ pointval.truncate(1);
+ pointval = "." + pointval;
+ }
+ if ( i == 4 ) {
+ pointval = QString::number(remainder);
+ pointval.truncate(2);
+ pointval = "." + pointval;
+ }
+
+ QString result = QString::number(bytes) + pointval;
return result += suffix[i];
}
More information about the Commits
mailing list