MCPcopy Create free account
hub / github.com/bbuchfink/diamond / convert_size

Function convert_size

src/util/string/string.cpp:45–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43using std::numeric_limits;
44
45string convert_size(size_t size) {
46 static const char *SIZES[] = { "B", "KB", "MB", "GB", "TB", "PB" };
47 size_t div = 0;
48 size_t rem = 0;
49
50 while (size >= 1024 && div < (sizeof SIZES / sizeof *SIZES)) {
51 rem = (size % 1024);
52 div++;
53 size /= 1024;
54 }
55
56 stringstream ss;
57 ss << std::fixed << std::setprecision(1) << (double)size + (double)rem / 1024.0 << ' ' << SIZES[div];
58 return ss.str();
59}
60
61namespace Util { namespace String {
62

Callers 1

log_rssFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected