Fix size formatting

The sizes were rounded up instead of down. This caused gigabyte sizes to
be shown in the terabyte range.
This commit is contained in:
Markus Mäkelä
2018-10-20 14:33:42 +03:00
parent aa8546ca80
commit c45059f83d
2 changed files with 5 additions and 4 deletions

View File

@ -59,7 +59,7 @@ namespace maxbase
std::string to_binary_size(int64_t size)
{
// Calculate log1024(size) and round it up
int idx = ceil(log(size) / log(1024));
int idx = floor(log(size) / log(1024));
double num = size / pow(1024, idx);
char buf[200]; // Enough for all possible values
snprintf(buf, sizeof(buf), "%.2lf%s", num, get_binary_size_suffix(idx));