MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / getFormattedByteSize

Function getFormattedByteSize

libs/string/format.h:9–27  ·  view source on GitHub ↗

Formats the given number in bytes/kB/MB/GB

Source from the content-addressed store, hash-verified

7
8// Formats the given number in bytes/kB/MB/GB
9inline std::string getFormattedByteSize(std::size_t size)
10{
11 if (size > 1024 * 1024 * 1024)
12 {
13 return fmt::format("{0:0.2f} GB", (static_cast<double>(size) / (1024 * 1024 * 1024)));
14 }
15 else if (size > 1024 * 1024)
16 {
17 return fmt::format("{0:0.1f} MB", (static_cast<double>(size) / (1024 * 1024)));
18 }
19 else if (size > 1024)
20 {
21 return fmt::format("{0:0.0f} kB", (static_cast<double>(size) / 1024));
22 }
23 else
24 {
25 return fmt::format("{0:d} bytes", size);
26 }
27}
28
29}

Callers 2

visitFileMethod · 0.85
printMemoryStatsMethod · 0.85

Calls 1

formatFunction · 0.50

Tested by

no test coverage detected