idk
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "stringutil.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <iomanip>
|
||||
@@ -424,3 +425,22 @@ std::vector<std::wstring> util::split(const std::wstring& str, char delimiter) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string util::format_data_size(size_t size) {
|
||||
if (size < 1024) {
|
||||
return std::to_string(size)+" B";
|
||||
}
|
||||
const std::string postfixes[] {
|
||||
" B", " KiB", " MiB", " GiB", " TiB", " EiB", " PiB"
|
||||
};
|
||||
int group = 0;
|
||||
size_t remainder;
|
||||
while (size >= 1024) {
|
||||
group++;
|
||||
remainder = size % 1024;
|
||||
size /= 1024;
|
||||
}
|
||||
return std::to_string(size)+"."+
|
||||
std::to_string(static_cast<int>(round(remainder/1024.0f)))+
|
||||
postfixes[group];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user