Bug Fix - formatBytes

- Corrected code and tests regarding floating point rounding.
This commit is contained in:
Paul Beckingham
2009-06-27 20:39:33 -04:00
parent 029b2d1182
commit 52052f91f9
2 changed files with 7 additions and 5 deletions

View File

@@ -184,9 +184,9 @@ std::string formatBytes (size_t bytes)
{
char formatted[24];
if (bytes >= 1000000000) sprintf (formatted, "%.1f GiB", (bytes / 1000000000.0));
else if (bytes >= 1000000) sprintf (formatted, "%.1f MiB", (bytes / 1000000.0));
else if (bytes >= 1000) sprintf (formatted, "%.1f KiB", (bytes / 1000.0));
if (bytes >= 995000000) sprintf (formatted, "%.1f GiB", (bytes / 1000000000.0));
else if (bytes >= 995000) sprintf (formatted, "%.1f MiB", (bytes / 1000000.0));
else if (bytes >= 995) sprintf (formatted, "%.1f KiB", (bytes / 1000.0));
else sprintf (formatted, "%d B", (int)bytes );
return commify (formatted);