COMMON: Update getHumanReadableBytes() in util.h
Function now casts bytes (as <1024) to unsigned long int to correspond "%lu" format string. For consistency, KB are now printed as floating number. Finally, it looks like double is pretty precise to be used in comparisons, so I made the function a little bit shorter.
This commit is contained in:
parent
16d97b6948
commit
7fc6477ce2
1 changed files with 9 additions and 16 deletions
|
@ -168,38 +168,31 @@ bool isGraph(int c) {
|
|||
|
||||
|
||||
Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) {
|
||||
Common::String result = Common::String::format("%lu", bytes);
|
||||
unitsOut = "B";
|
||||
|
||||
if (bytes >= 1024) {
|
||||
bytes /= 1024;
|
||||
result = Common::String::format("%lu", bytes);
|
||||
unitsOut = "KB";
|
||||
if (bytes < 1024) {
|
||||
unitsOut = "B";
|
||||
return Common::String::format("%lu", (unsigned long int)bytes);
|
||||
}
|
||||
|
||||
double floating = bytes;
|
||||
double floating = bytes / 1024.0;
|
||||
unitsOut = "KB";
|
||||
|
||||
if (bytes >= 1024) {
|
||||
bytes /= 1024;
|
||||
if (floating >= 1024) {
|
||||
floating /= 1024.0;
|
||||
unitsOut = "MB";
|
||||
}
|
||||
|
||||
if (bytes >= 1024) {
|
||||
bytes /= 1024;
|
||||
if (floating >= 1024) {
|
||||
floating /= 1024.0;
|
||||
unitsOut = "GB";
|
||||
}
|
||||
|
||||
if (bytes >= 1024) { // woah
|
||||
bytes /= 1024;
|
||||
if (floating >= 1024) { // woah
|
||||
floating /= 1024.0;
|
||||
unitsOut = "TB";
|
||||
}
|
||||
|
||||
// print one digit after floating point
|
||||
result = Common::String::format("%.1f", floating);
|
||||
return result;
|
||||
return Common::String::format("%.1f", floating);
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue