mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-08 00:36:11 +00:00
add ToHumanReadableSize, which formats data sizes into MiB, GiB, etc.
this is needed in order to display data sizes in upcoming changes related to tracking statistics about the server's performance
This commit is contained in:
@@ -427,3 +427,17 @@ std::string GetPlatformAgnosticErrorString() {
|
||||
return "(no human-readable errors on this platform)";
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ToHumanReadableSize(size_t Size) {
|
||||
if (Size > TB) {
|
||||
return fmt::format("{:.2f} TiB", double(Size) / TB);
|
||||
} else if (Size > GB) {
|
||||
return fmt::format("{:.2f} GiB", double(Size) / GB);
|
||||
} else if (Size > MB) {
|
||||
return fmt::format("{:.2f} MiB", double(Size) / MB);
|
||||
} else if (Size > KB) {
|
||||
return fmt::format("{:.2f} KiB", double(Size) / KB);
|
||||
} else {
|
||||
return fmt::format("{} B", Size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user