fromBytes

v1
Brett 2023-03-05 17:06:07 -05:00
parent 831a485209
commit 62d929171c
1 changed files with 15 additions and 0 deletions

View File

@ -12,6 +12,21 @@
#include <vector> #include <vector>
namespace blt::string { namespace blt::string {
static inline std::string fromBytes(unsigned long bytes){
if (bytes > 1073741824) {
// gigabyte
return std::to_string((double)bytes / 1024.0 / 1024.0 / 1024.0) += "gb";
} else if (bytes > 1048576) {
// megabyte
return std::to_string((double)bytes / 1024.0 / 1024.0) += "mb";
} else if (bytes > 1024) {
// kilobyte
return std::to_string((double)bytes / 1024.0) += "kb";
} else {
return std::to_string(bytes) += "b";
}
}
// TODO template the padding functions: // TODO template the padding functions:
/** /**