Last active
July 25, 2022 22:51
-
-
Save idolpx/735694e2b35e41556987d37eb5078528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string byteSuffixes[9] = { "", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; | |
std::string formatBytes(uint64_t value) { | |
uint8_t i = 0; | |
double n = 0; | |
char *f = NULL; | |
do { | |
i++; | |
n = value / std::pow(1024, ++i); | |
} while ( n >= 1 ); | |
n = value / std::pow(1024, --i); | |
asprintf(&f, "%.2f %s", n, byteSuffixes[i].c_str()); | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment