fs: Fix wrong size report

This commit is contained in:
Nicolò Balzarotti
2017-03-12 14:49:10 +01:00
parent 9a72584680
commit 84ee0d560c
2 changed files with 12 additions and 7 deletions

View File

@ -257,15 +257,16 @@ namespace string_util {
/**
* Create a filesize string by converting given bytes to highest unit possible
*/
string filesize(unsigned long long kbytes, size_t precision, bool fixed, const string& locale) {
vector<string> suffixes{"TB", "GB", "MB"};
string suffix{"KB"};
double value = kbytes;
while (!suffixes.empty() && (value /= 1024.0) >= 1024.0) {
string filesize(unsigned long long bytes, size_t precision, bool fixed, const string& locale) {
vector<string> suffixes{"TB", "GB", "MB", "KB"};
string suffix{"B"};
double value = bytes;
while (!suffixes.empty() && value >= 1024.0) {
suffix = suffixes.back();
suffixes.pop_back();
value /= 1024.0;
}
return floating_point(value, precision, fixed, locale) + " GB";
return floating_point(value, precision, fixed, locale) + " " + suffix;
}
/**