MCPcopy Create free account
hub / github.com/BruceDevices/firmware / formatBytes

Function formatBytes

src/core/utils.cpp:301–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301String formatBytes(uint64_t bytes) {
302 const char *units[] = {"B", "KB", "MB", "GB", "TB"};
303 int unitIndex = 0;
304 float size = bytes;
305
306 while (size >= 1024.0 && unitIndex < 4) {
307 size /= 1024.0;
308 unitIndex++;
309 }
310
311 if (unitIndex == 0) {
312 return String(bytes) + " " + units[unitIndex];
313 } else {
314 return String(size, 2) + " " + units[unitIndex];
315 }
316}

Callers 1

showDeviceInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected