[PC-BSD Commits] r6432 - pcbsd/trunk/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Tue Mar 23 11:38:32 PDT 2010


Author: kris
Date: 2010-03-23 11:38:32 -0700 (Tue, 23 Mar 2010)
New Revision: 6432

Modified:
   pcbsd/trunk/libpcbsd/utils.cpp
Log:

Fix bytes to human readable to show two digits after . giving greater accuracy for memory reporting
to the end user



Modified: pcbsd/trunk/libpcbsd/utils.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/utils.cpp	2010-03-23 17:13:20 UTC (rev 6431)
+++ pcbsd/trunk/libpcbsd/utils.cpp	2010-03-23 18:38:32 UTC (rev 6432)
@@ -49,12 +49,16 @@
 QString Utils::bytesToHumanReadable(long long bytes)
 {
    QString suffix[] = {"B", "KB", "MB", "GB", "TB"};
+   long long remainder;
    int i = 0;
    while((bytes >= 1000) && (i < 4))
    {
+      remainder = bytes % 1024;
       bytes = bytes / 1024;
       i++;
    }
-   QString result = QString::number(bytes, 'f', 0);
+   QString pointval = QString::number(remainder);
+   pointval.truncate(2);
+   QString result = QString::number(bytes) + "." + pointval;
    return result += suffix[i];
 }



More information about the Commits mailing list