MCPcopy Create free account
hub / github.com/Universal-Team/Universal-Updater / formatBytes

Method formatBytes

source/utils/stringutils.cpp:74–85  ·  view source on GitHub ↗

adapted from GM9i's byte parsing. */

Source from the content-addressed store, hash-verified

72 adapted from GM9i's byte parsing.
73*/
74std::string StringUtils::formatBytes(u64 bytes) {
75 char out[32];
76
77 if (bytes == 1) snprintf(out, sizeof(out), "%lld Byte", bytes);
78 else if (bytes < 1ull << 10) snprintf(out, sizeof(out), "%lld Bytes", bytes);
79 else if (bytes < 1ull << 20) snprintf(out, sizeof(out), "%.1f KiB", (float)bytes / 1024);
80 else if (bytes < 1ull << 30) snprintf(out, sizeof(out), "%.1f MiB", (float)bytes / 1024 / 1024);
81 else if (bytes < 1ull << 40) snprintf(out, sizeof(out), "%.1f GiB", (float)bytes / 1024 / 1024 / 1024);
82 else snprintf(out, sizeof(out), "%.1f TiB", (float)bytes / 1024 / 1024 / 1024 / 1024);
83
84 return out;
85}
86
87/*
88 Format a number with separators per locale

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected